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?
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.
List<String> list = Arrays. asList("abc", "def", "ghi"); List<String> upped = list. stream(). map(String::toUpperCase).
Use string upper() method to convert every element in a list of strings into uppercase (capitalize) in Python code.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With