This post will discuss how to convert list of Integer to list of string in Java.

1. Using Java 8

We can use Java 8 Stream to convert List<Integer> to List<String>. Following are the complete steps:

  1. Convert List<Integer> to Stream<Integer> using List.stream().
  2. Convert Stream<Integer> to Stream<String> using Stream.map().
  3. Accumulate Stream<String> into List<String> using Collectors.toList().

The following program demonstrates it:

Download  Run Code

 
It is recommended to use method references for referring to an existing method instead of a lambda expression. For converting an integer to a string, we can pass String::valueOf to the map() method.

Using Generics:

Following is the generic version of the above program. It passes the method reference as a parameter to the generic function.

Download  Run Code

 
Here’s an equivalent version without using the Stream API.

Download  Run Code

2. Using Guava Library

 
1. Guava’s Lists class provides the transform() method that returns a list that applies a specified method to each element of the specified list. This transformation happens in such a way that any changes to the original list will be reflected in the returned list, but no new items can be added to the returned list.

Download Code

 
2. We can also transform a list using Guava’s Iterables.transform(). It returns a view containing the result of applying a method to each list element.

Download Code

 
Here’s how we can call Iterables.transform() with Java 7 and before:

 
3. Similar to Iterables.transform(), we can also use Collections2.transform() that returns a collection, as shown below:

Download Code

 
Here’s how we can call Collections2.transform() with Java 7 and before:

That’s all about converting Integer List to List of Java String.