File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 11import java .util .HashSet ;
2+ import java .util .Set ;
3+ import java .util .stream .Collectors ;
24
35
46public class HashSetDemo15g {
@@ -10,6 +12,11 @@ public static void main(String[] args) {
1012 set1 .add (2 );
1113 set1 .add (3 );
1214 set1 .add (4 );
15+ set1 .add (6 );
16+ set1 .add (7 );
17+ set1 .add (8 );
18+ set1 .add (9 );
19+ set1 .add (10 );
1320
1421 set2 .add ("A" );
1522 set2 .add ("a" );
@@ -22,10 +29,18 @@ public static void main(String[] args) {
2229 boolean c = set2 .stream ().dropWhile (s -> s .length () == 1 ).noneMatch (s -> s .length () == 1 );
2330 boolean d = set2 .stream ().dropWhile (s -> s == "A" ).anyMatch (s -> s == "A" );
2431
25-
32+ Set <Integer > set3 = set1 .stream ().dropWhile (s -> (s ==1 )).collect (Collectors .toSet ());
33+ HashSet <Integer >set4 = set1 .stream ().dropWhile (s -> ((s / 2 )==1 )).collect (Collectors .toCollection (HashSet ::new ));
34+ HashSet <Integer > set5 = set1 .stream ().dropWhile (s -> (s == 1 ))
35+ .collect (HashSet ::new , HashSet ::add , HashSet ::addAll );
2636 System .out .println (b );
2737 System .out .println (c );
2838 System .out .println (d );
39+ System .out .println (set3 );
40+ System .out .println (set4 );
41+ System .out .println (set5 );
42+
43+
2944
3045
3146 }
You can’t perform that action at this time.
0 commit comments