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

Java 8Object Oriented ProgrammingProgramming

Here’s our List of Integer −

List<Integer> listInteger = Arrays.asList(25, 50, 75, 100, 125, 150);

Now, convert List of Integer to List of String −

List<String> listString = listInteger.stream()
   .map(s -> String.valueOf(s))
   .collect(Collectors.toList());

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

Example

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

Output

List of Integer = [25, 50, 75, 100, 125, 150]
List of String (converted from List of Integer) = [25, 50, 75, 100, 125, 150]
raja
Published on 23-Sep-2019 16:25:57
Advertisements