CodesJava

Easy learning with example program codes

java 8 stream sorted method example

The java.util.stream is a sequence of elements supporting sequential and parallel aggregate operations.
The Stream.sorted() method returns a sorted Stream.

Java 8 stream sorted method example

package com.codesjava;
 
import java.util.stream.Stream;
 
public class Test{  
    public static void main(String[] args) {  
    	Stream.of("Jai", "Mahesh", "Vishal", "Naren", "Hemant")
    	.sorted()
        .forEach(System.out::println);
    }  
}

Output

Hemant
Jai
Mahesh
Naren
Vishal
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status