Java Collection Exercises 3

Source: Internet
Author: User

Creates a map collection, creates an EMP object, and creates an EMP object in the field collection (the ID of the EMP object as the key to the Map collection), and removes the object with ID 005 from the collection.

 PackageCom.hanqi.jihe; Public classEMP {PrivateString e_id; PrivateString E_name;  PublicEmp (String e_id,string e_name) { 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.hanqi.jihe;ImportJava.util.*; Public classTESTMAP2 { Public Static voidMain (string[] args) {Map<String,String> map=NewHashmap<>(); EMP e=NewEMP ("001", "one"); EMP E2=NewEMP ("003", "three"); EMP E3=NewEMP ("005", "five"); EMP e4=NewEMP ("007", "seven");        Map.put (e.gete_id (), E.gete_name ());        Map.put (e2.gete_id (), E2.gete_name ());        Map.put (e3.gete_id (), E3.gete_name ());        Map.put (e4.gete_id (), E4.gete_name ()); Map.Remove ("005"); Set Set=Map.keyset (); Iterator<string>it=Set.iterator ();  while(It.hasnext ()) {String s=It.next (); String N=Map.get (s); System.out.println (S+" "+N); }    }}

Java Collection Exercises 3

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.