Syntax error Program to convert List of String to List of Integer in Java

Program to convert List of String to List of Integer in Java



Here’s our List of String −

List<String> listString = Arrays.asList("25", "50", "75", "100", "125", "150");

Now, convert the list of string to list of integer −

List<Integer> listInteger = listString.stream().map(Integer::parseInt).collect(Collectors.toList());

Following is the program to convert List of String to List of Integer in Java −

Example

import java.util.*;
import java.util.stream.*;
import java.util.function.*;
public class Demo {
   public static void main(String[] args) {
      List<String> listString = Arrays.asList("25", "50", "75", "100", "125", "150");
      System.out.println("List of String = " + listString);
      List<Integer> listInteger = listString.stream().map(Integer::parseInt)
         .collect(Collectors.toList());
      System.out.println("List of Integer (converted from List of String) = " + listInteger);
   }
}

Output

List of String = [25, 50, 75, 100, 125, 150]
List of Integer (converted from List of String) = [25, 50, 75, 100, 125, 150]
Updated on: 2019-09-23T12:58:22+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements