File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import java .util .HashMap ;
2- import java .util .Iterator ;
3- import java .util .Map ;
1+ import java .util .*;
2+ import java .util .concurrent .ConcurrentHashMap ;
43
54public class MapDemo {
65 public static void main (String [] args ) {
76 Map <String , String > map = new HashMap <>();
87 map .put ("1" , "Value1" );
98 map .put ("2" , "Value2" );
109 map .put ("3" , "Value3" );
10+ map .put (null , "11" );
1111 //第一种:普遍使用,二次取值
1212 System .out .println ("通过Map.keySet遍历key和value:" );
1313 for (String key :
@@ -31,5 +31,12 @@ public static void main(String[] args) {
3131 ) {
3232 System .out .println ("key=" + entry .getKey () + " and value=" + entry .getValue ());
3333 }
34+ Vector vector = new Vector ();
35+ vector .add ("11" );
36+
37+ // Map<String,Integer> stringIntegerMap=new ConcurrentHashMap<>();
38+ // stringIntegerMap.put(null,11);
39+ HashSet hashSet = new HashSet ();
40+ hashSet .add (11 );
3441 }
3542}
Original file line number Diff line number Diff line change @@ -27,10 +27,27 @@ public static void main(String[] args) {
2727 System .out .println (stringBuffer );
2828 System .out .println (stringBuffer .reverse ());
2929
30- StringBuilder sb = new StringBuilder ("Test1" );
31- int size = sb .capacity ();
30+ StringBuilder sb = new StringBuilder ("Test1" );
31+ int size = sb .capacity ();
3232 System .out .println (size );
3333
34+ //System.exit(0);
35+
36+ String aa = new String ("ab" );
37+ String bb = new String ("ab" );
38+ String aaa = "ab" ;
39+ String bbb = "ab" ;
40+ System .out .println (aa .hashCode ()+"/" +bb .hashCode ()+"/" +aaa .hashCode ()+"/" +bbb .hashCode ());
41+ if (aa == bb )
42+ System .out .println ("aa==bb" );
43+ if (aaa == bbb )
44+ System .out .println ("aaa==bbb" );
45+ if (aa .equals (bb ))
46+ System .out .println ("aa equals bb" );
47+ if (aaa .equals (bbb ))
48+ System .out .println ("aaa equals bbb" );
49+
50+
3451 }
3552}
3653
You can’t perform that action at this time.
0 commit comments