Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Returning a Collection instead of Stream in Java 8?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 257
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: