File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ public static void main(String[] args) {
1818 map .values ()) {
1919 System .out .println (value );
2020 }
21+
2122 //第二种
2223 System .out .println ("通过Map.entrySet使用iterator遍历key和value:" );
2324 Iterator <Map .Entry <String , String >> iterator = map .entrySet ().iterator ();
@@ -31,6 +32,9 @@ public static void main(String[] args) {
3132 ) {
3233 System .out .println ("key=" + entry .getKey () + " and value=" + entry .getValue ());
3334 }
35+ //第四种:尤其推荐
36+ map .forEach ((k , v ) -> System .out .println ("Key=" + k + ",Value=" + v ));
37+
3438 Vector vector = new Vector ();
3539 vector .add ("11" );
3640
Original file line number Diff line number Diff line change 1+ import java .time .LocalDate ;
2+ import java .util .PriorityQueue ;
3+
4+ public class PriorityQueueDemo {
5+ public static void main (String [] args ) {
6+ PriorityQueue <LocalDate > pq = new PriorityQueue <>();
7+ pq .add (LocalDate .of (1906 , 12 , 9 ));
8+ pq .add (LocalDate .of (1815 , 12 , 10 ));
9+ pq .add (LocalDate .of (1903 , 12 , 3 ));
10+ pq .add (LocalDate .of (1910 , 6 , 22 ));
11+ System .out .println ("Iterating over elements..." );
12+ for (LocalDate date : pq ) {
13+ System .out .println (date );
14+ }
15+ System .out .println ("Removing elements...." );
16+ while (!pq .isEmpty ()) {
17+ System .out .println (pq .remove ());
18+ }
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ import java .util .ArrayList ;
2+ import java .util .Collections ;
3+ import java .util .List ;
4+
5+ //随机的混排列表中元素的顺序
6+ public class ShuffleDemo {
7+ public static void main (String [] args ) {
8+ List <Integer > numbers = new ArrayList <>();
9+ for (int i = 0 ; i <= 49 ; i ++) {
10+ numbers .add (i );
11+ }
12+ Collections .shuffle (numbers );
13+ List <Integer > winningCombination = numbers .subList (0 , 6 );
14+ Collections .sort (winningCombination );
15+ System .out .println (winningCombination );
16+ }
17+ }
You can’t perform that action at this time.
0 commit comments