Convert a list of integers to a list of strings
suggest changeList<Integer> nums = Arrays.asList(1, 2, 3);
List<String> strings = nums.stream()
.map(Object::toString)
.collect(Collectors.toList());
That is:
- Create a stream from the list
- Map each element using
Object::toString
- Collect the
String
values into aList
usingCollectors.toList()
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents