How to print sorted stream in ascending order with Java

1 Answer

0 votes
import java.util.stream.Stream;

public class MyClass {
    public static void main(String args[]) {
        Stream<Integer> stream = Stream.of(4, 6, 0, 7, 3, 1); 
        
        stream.sorted().forEach(System.out::println); 
    }
}




/*
run:

0
1
3
4
6
7

*/

 



answered Jun 6, 2023 by avibootz

Related questions

...