1) Sort number in given integer using stream in ascending order
import java.util.ArrayList;
import java.util.List;
public class javaStreamExamples {
List<Integer> list1=Arrays.asList(10,20,35,20,67,10)
public void testStream(){
Set<Integer> set1= new HashSet();
list1.stream().sorted().forEach(System.out::println);
}
}
O/p
10
10
20
20
35
67
==================================================
1) Sort number in given integer using stream in Descending order
import java.util.ArrayList;
import java.util.List;
public class javaStreamExamples {
List<Integer> list1=Arrays.asList(10,20,35,20,67,10)
public void testStream(){
Set<Integer> set1= new HashSet();
list1.stream().sorted(Collections.reverseOrder()).forEach(System.out::println);
}
}
O/p
67
35
20
20
10
10
==================================================
No comments:
Post a Comment