HashMap key and value values are strong references, meaning that the HashMap object is not destroyed when the key value pair is not destroyed, but Weakhashmap, when the inside of the key value is not destroyed when the words may be automatically destroyed by the Java recycling mechanism
Weakhashmap whm=new weakhashmap<> ();
Whm.put (New String ("PHP"), "75 Yuan");
Whm.put (New String ("Java"), "90 Yuan");
System.GC ();
System.runfinalization ();
System.out.println (WHM);
HashMap whm1=new HashMap ();
Whm1.put (New String ("PHP"), "75 Yuan");
Whm1.put (New String ("Java"), "90 Yuan");
Forcing the system to be garbage collected
System.GC ();
System.runfinalization ();
System.out.println (WHM1);
{}
{php=75 yuan, java=90 yuan}
There are two ways to determine whether two variables are equal in Java: One is to use the = = operator, and the other is to take advantage of the Equals method. If the variable is a basic type, then using = = and using equals results in the same result, which determines whether the value of the variable is relative. If the variable is a reference type, the = = operator Determines whether the variable points to the same reference object, and equals determines whether the variable "value" is equal. The wrapper class for the Java value type (Boolean, Byte, short, Integer, Long, Float, Double, charcater) can be judged by the = = operator.
- int inta = 65;
- float floata = 65.0f;
- Integer INTB = 65;
- Float FLOATB = 65.0f;
- INTA = = Floata According to the value, the result is true
- System.out.println ("Inta = = Floata:" + (Inta = = Floata));
- INTA = = INTB According to the value, the result is true
- System.out.println ("Inta = = Intb:" + (Inta = = INTB));
- INTA = = FLOATB According to the value, the result is true
- System.out.println ("Inta = = FLOATB:" + (Inta = = FLOATB));
- String stra = "Test";
- String strb = new String ("test");
- String strc = new String ("test");
- String STRD = "Test";
- Stra and Strb point to different objects and the result is false
- System.out.println ("stra = = strb:" + (Stra = = STRB));
- Stra and Strd point to the same object, and the result is true
- System.out.println ("stra = = strd:" + (Stra = = STRD));
- STRB and Strc point to different objects and the result is false
- System.out.println ("STRB = = strc:" + (STRB = = strc));
- STRB and STRC are the same values, the result is true
- System.out.println ("Strb equals strc:" + (Strb.equals (STRC)));
- Stra and STRB are the same values, the result is true
- System.out.println ("Stra equals STRB:" + (Stra.equals (STRB)));
Java Review-hashmap and Weakhashmap