Basic applications for MAP collections:
Map<integer,student> map=new hashmap<integer,student> ();
Map.put (1, New Student (1, "Zhang San", "male", 23));
Map.put (2, New Student (2, "Vince", "female", 21));
Map.put (3, New Student (3, "Wang Lu", "male", 34));
Map.put (4,new Student (4, "Liu Wei", "female", 35));
Based on the key object, the value object is found, the value object is returned, and NULL is returned if there is no corresponding Key object.
Student S=map.get (3);
According to the Key object, remove
Map.Remove (2);
Traverse. Get the set set of a key object first
Set <integer>set=map.keyset ();
for (Integer Ss:set) {
System.out.println ("Key:" +ss+ "Value:" +map.get (ss));
}
Application of List
List list=new ArrayList ();
Append element
List.add ("AAAA");
List.add (New JButton ());
List.add (New JFrame ());
List.add (New JLabel ());
List.add ("BBB");
Get the Set length
System.out.println (List.size ());
for (int i=0;i<list.size (); i++) {
Remove the first element i
Object Obj=list.get (i);
System.out.println (Obj.tostring ());
}
Only objects of type string can be placed in the collection;
List<string> x=new arraylist<string> ();
X.add ("AAA");
The object in the collection can only be placed in an integer type;
List<integer> y=new arraylist<integer> ();
Y.add (3);//Auto-boxing, 3=new Integer (3);
Y.add (New Integer (2));
}
Basic application of list set and set set