To convert a list of strings to uppercase in Java, you can use the List.replaceAll()
method. The List.replaceAll()
method replaces each list element with the result of applying the operator to that element.
// Declare a list
List<String> list = Arrays.asList("a", "b", "c");
// Uppercase the list
list.replaceAll(String::toUpperCase);
// Print list elements
list.forEach(System.out::println);
// A
// B
// C
Alternatively, you can use the Streams API map()
method to transfer a list of strings to uppercase in Java:
// Declare a list
List<String> list = Arrays.asList("a", "b", "c");
// Uppercase the list
list = list.stream().map(String::toUpperCase).collect(Collectors.toList());
// Print list elements
list.forEach(System.out::println);
// A
// B
// C
✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed.