Convert String Objects in Collection to Uppercase Using Stream concept




Stream concept has been introduced in Java 8 . Stream concept is used to work on collection objects.

For converting String objects contained in collection to uppercase, we would be using map() method of Stream class.

map() method of Stream class is used to modify the objects contained in collection and returns a stream consisting of the results of applying the given function to the elements of the stream.

Example to Convert String Objects in Collection to Uppercase Using Stream concept:

package com.masterjavatutorial;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test {
    public static void main(String[] args) {
	
        List list = new ArrayList();
        list.add("HelloWorld");
        list.add("india");
        list.add("kiran");
        list.add("delhi");
        
        Stream stream = list.stream(); 
        List strInUppercaseList = stream.map(s-> s.toUpperCase()).collect(Collectors.toList()); 
        System.out.println(strInUppercaseList); 
        
    }

}


Output of the above program is as below:

[HELLOWORLD, INDIA, KIRAN, DELHI]