Java Collection exercise: Create a Map collection, create an EMP object, and add the created EMP object to the collection

Source: Internet
Author: User
Tags set set

 PackageCom.jihe; Public classEMP {PrivateString e_id; PrivateString E_name;  PublicEmp (String e_id, String e_name) {Super();  This. e_id =e_id;  This. E_name =E_name; }     PublicString gete_id () {returne_id; }     Public voidsete_id (String e_id) { This. e_id =e_id; }     PublicString Gete_name () {returnE_name; }     Public voidsete_name (String e_name) { This. E_name =E_name; }    }
 PackageCom.jihe;ImportJava.util.*; Public classEmpmap { Public Static voidMain (string[] args) {Map<String,String> map=NewHashMap (); EMP EMP=NewEMP ("001", "Zhang San"); EMP EMP1=NewEMP ("005", "John Doe"); EMP EMP2=NewEMP ("003", "Harry"); EMP Emp3=NewEMP ("008", "Zhao Liu");        Map.put (emp.gete_id (), Emp.gete_name ());        Map.put (emp1.gete_id (), Emp1.gete_name ());        Map.put (emp2.gete_id (), Emp2.gete_name ());        Map.put (emp3.gete_id (), Emp3.gete_name ()); Set<String> keys=Map.keyset (); System.out.println ("Traverse Collection Map:"); Iterator<String> it=Keys.iterator ();  while(It.hasnext ()) {String key=It.next (); SYSTEM.OUT.PRINTLN (Key+" "+Map.get (key)); } System.out.println ("Removed is" +map.remove ("005")); Map<string,string>treemap=NewTreeMap ();        Treemap.putall (map); Set Set=Treemap.keyset (); System.out.println ("Traversing collection TreeMap:"); Iterator<String> ss=Set.iterator ();  while(Ss.hasnext ()) {String str=Ss.next (); System.out.println (str+" "+treemap.get (str)); }    }}

Java Collection Exercise: Create a Map collection, create an EMP object, and add the created EMP object to the collection

Related Article

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.