Java Program: Convert List of Strings to Uppercase or Lowercase using Streams
Write a Java program to convert a list of strings to uppercase or lowercase using streams.
Sample Solution:
Java Code:
Sample Output:
List of strings: [RED, grEEn, white, Orange, pink] Uppercase Strings: [RED, GREEN, WHITE, ORANGE, PINK] Lowercase Strings: [red, green, white, orange, pink]
Explanation:
In the above exercises, we have a list of strings containing ("RED", "grEEn", "white", "Orange", "pink"). Using streams. First convert the strings to uppercase by calling the toUpperCase method on each string, and then collect the results into a new list using the collect method. Similarly, convert the strings to lowercase by calling the toLowerCase method on each string. Finally, the uppercase and lowercase lists are printed to the console.
Flowchart:
Java Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Calculate Average of Integers using Streams.
Next: Sum of Even and Odd Numbers in a List using Streams.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics