What is the lambda expression to convert array/List of String to array/List of Integers in java?



You can convert an array list of strings to an array list of integers as:

Example

Live Demo

import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class LamdaExpressions {    public static void main(String args[]) {       ArrayList <String> list = new ArrayList<String>();       list.add("123");       list.add("223");       list.add("323");       list.add("334");       List<Integer> listInteger =          list.stream().map(s -> Integer.parseInt(s)).collect(Collectors.toList());       System.out.println(listInteger);    } }

Output

[123, 223, 323, 334]
Updated on: 2020-06-16T10:12:36+05:30

844 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements