Basic application of list set and set set

Source: Internet
Author: User
Tags set set

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.