Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform all elements of a list of strings to upper case [duplicate]

Tags:

I want to transform a list of strings to upper case.

Here's my code to do this:

List<String> list = Arrays.asList("abc", "def", "ghi"); List<String> upped = list.stream().map(String::toUpperCase).collect(Collectors.toList()); 

Is there a simpler/better way to do this?

like image 608
lapots Avatar asked Feb 14 '16 18:02

lapots


People also ask

How can I uppercase all strings in a list?

Uppercase. To turn a string to uppercase in Python, use the built-in upper() method of a string. To turn a list of strings to uppercase, loop through the list and convert each string to upper case.

How do you uppercase a list in Java?

List<String> list = Arrays. asList("abc", "def", "ghi"); List<String> upped = list. stream(). map(String::toUpperCase).

How do you uppercase an array in Python?

Use string upper() method to convert every element in a list of strings into uppercase (capitalize) in Python code.

How do I convert all strings to lowercase?

lower() Function and a for Loop to Convert a List of Strings to Lowercase in Python. The str. lower() method is utilized to simply convert all uppercase characters in a given string into lowercase characters and provide the result.


Video Answer


1 Answers

You have not actually transformed the list; you have created a new list.

To transform the list in one small method call, use List#replaceAll():

list.replaceAll(String::toUpperCase); 
like image 58
Bohemian Avatar answered Sep 19 '22 13:09

Bohemian