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


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]

Updated on: 23-Sep-2019

518 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements