private static void m2() {
List<Integer> list=Data.getIntList(10);
list.stream().forEach(n->System.out.print(n+", "));
System.out.println();
list.stream().sorted().forEach(n->System.out.print(n+", "));
System.out.println();
list.stream().sorted(new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
return o1-o2;
};
}).forEach(n->System.out.print(n+", "));
System.out.println();
list.stream().sorted((o1, o2)->o1-o2)
.forEach(n->System.out.print(n+", "));
System.out.println();
list.stream().sorted((o1, o2)->o2-o1)
.forEach(n->System.out.print(n+", "));
System.out.println();
list.stream().sorted(Comparator.reverseOrder())
.forEach(n->System.out.print(n+", "));
System.out.println();
list.stream()
.filter(num->num%2==0)
.distinct()
.sorted()
.forEach(num->System.out.print(num+", "));
Data.getItemList().stream()
.filter(item->item.getColor()==Color.BLACK)
.sorted((o1, o2) -> o1.getSize()-o2.getSize())
.forEach(item->System.out.println(item));
}
private static void m1() {
List<Integer> nums=Data.getIntList(20);
System.out.println(nums);
nums.stream().forEach(n->{
if (n%2==0) {
System.out.print(n+", ");
}
});
nums.stream().filter(num->num%2==0)
.forEach(num->System.out.print(num+", "));
Data.getUserList().stream()
.filter(user->user.getGender()==1)
.forEach(user->System.out.println(user));
System.out.println();
Data.getUserList().stream()
.filter(user->user.getHeight()>=170&&user.getWeight()<=75)
.forEach(user->System.out.println(user));
System.out.println();
Data.getUserList().stream()
.filter(user->user.getHeight()>=170)
.filter(user->user.getWeight()<=75)
.forEach(user->System.out.println(user));
System.out.println();
Data.getItemList().stream()
.filter(item->item.getColor()==Color.YELLOW)
.filter(item->item.getDate().get(Calendar.DAY_OF_WEEK)==7)
.forEach(item->System.out.println(item));
System.out.println();
}