In Java 8, the Streams is the new addition in the Java Collections API. It is the new method to process collections of objects. That is a different concept than the IO streams in the Java . Streams can be designed to work with Java lambda expressions.
The Below code will show you how you can return the Collection using the Stream.
import java.util.*;
import java.util.stream.*;
class Demo
{
public static void main(String ss[])
{
List<String> list=new ArrayList<String>();
list.add("babita");
list.add("pooja");
list.add("swati");
list.add("nanda");
list.add("nidhi");
/* Returns the Stream from Collection*/
Stream<String> stream=list.stream();
/* Returns the Collections from Stream */
List<String> names=stream.map(item->item.toUpperCase()).collect(Collectors.toList());
System.out.println("Names :"+names);
}
}
Hope this will help you :)
0 Comment(s)