Convert list of strings to uppercase and lowercase using Lambda expression in Java
3. Convert strings to upper/lowercase using lambda
Write a Java program to implement a lambda expression to convert a list of strings to uppercase and lowercase.
Sample Solution:
Java Code:
Sample Output:
Original strings: Red Green Blue PINK Lowercase strings: red green blue pink Uppercase strings: RED GREEN BLUE PINK
Explanation:
In the above exercise, we start by creating a list of strings stringList.
The replaceAll() method applies a lambda expression that converts each string in the list to uppercase using the toUpperCase() method. This lambda expression is (str -> str.toUpperCase()). After that, the replaceAll() method applies a lambda expression that converts each string in the list to lowercase using the toLowerCase method. This lambda expression is (str -> str.toLowerCase()).
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Java program to implement a lambda expression that converts a list of strings to title case.
- Write a Java program to create a lambda that simultaneously returns two lists: one with uppercase and one with lowercase versions.
- Write a Java program to implement a lambda that maps a list of mixed-case strings to a list of alternating uppercase and lowercase letters.
- Write a Java program to chain lambda expressions to convert a list of strings first to uppercase and then sort them alphabetically.
Go to:
PREV : Check if a string is empty using lambda.
NEXT : Filter even and odd numbers with lambda.
Live Demo:
Java Code Editor:
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.