How to convert List<Integer> to List<String> in Java

1 Answer

0 votes
import java.util.List;
import java.util.Arrays;
import java.util.stream.Collectors;

public class MyClass {
    public static void main(String args[]) {
        List<Integer> list_integers = Arrays.asList(1, 2, 3, 4, 5, 6);
        
        List<String> list_strings = list_integers.stream().map(Object::toString)
                                        .collect(Collectors.toList());

        System.out.println(list_strings);
    }
}




/*
run:

[1, 2, 3, 4, 5, 6]

*/

 



answered Jun 12, 2023 by avibootz

Related questions

1 answer 151 views
1 answer 96 views
2 answers 168 views
1 answer 135 views
1 answer 143 views
1 answer 116 views
...