-
Notifications
You must be signed in to change notification settings - Fork 1
/
HashSetDemo15g.java
48 lines (37 loc) · 1.48 KB
/
HashSetDemo15g.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
public class HashSetDemo15g {
public static void main(String[] args) {
HashSet<Integer> set1 = new HashSet<>();
HashSet<String> set2 = new HashSet<>();
set1.add(1);
set1.add(2);
set1.add(3);
set1.add(4);
set1.add(6);
set1.add(7);
set1.add(8);
set1.add(9);
set1.add(10);
set2.add("A");
set2.add("a");
set2.add("B");
set2.add("b");
set2.add("C");
set2.add("c");
boolean b = set2.stream().dropWhile(s -> s.length() == 1).allMatch(s -> s.length() == 1);
boolean c = set2.stream().dropWhile(s -> s.length() == 1).noneMatch(s -> s.length() == 1);
boolean d = set2.stream().dropWhile(s -> s == "A").anyMatch(s -> s== "A");
Set<Integer> set3 = set1.stream().dropWhile(s -> (s==1)).collect(Collectors.toSet());
HashSet<Integer>set4 = set1.stream().dropWhile(s -> ((s / 2)==1)).collect(Collectors.toCollection(HashSet::new));
HashSet<Integer> set5 = set1.stream().dropWhile(s -> (s == 1))
.collect(HashSet::new, HashSet::add, HashSet::addAll);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(set3);
System.out.println(set4);
System.out.println(set5);
}
}