Java Collection Exercise--3

Source: Internet
Author: User

Creates a map collection, creates an EMP object, adds the created EMP object to the collection, and removes the object with ID 005 from the collection

To create an EMP class:

Package Jihe;public class Emp {private string Id;public string GetId () {return ID;} public void SetId (String id) {this.id = ID;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} private string Name;public EMP (string ID, string name) {super (); this.id = Id;this.name = name;}

Create a Map class and test:

Package Jihe;import java.util.*;p ublic class Lianxi1 {public static void main (string[] args) {map<string,string> ma P=new hashmap<> (); EMP emp=new EMP ("001", "Hamburg"); EMP emp1=new EMP ("002", "french fries"); EMP emp2=new EMP ("003", "coffee"); EMP emp3=new EMP ("004", "milk"); EMP emp4=new EMP ("005", "chicken Wings"); EMP emp5=new EMP ("006", "chicken Leg"), Map.put (Emp.getid (), Emp.getname ()), Map.put (Emp1.getid (), Emp1.getname ()), Map.put ( Emp2.getid (), Emp2.getname ()), Map.put (Emp3.getid (), Emp3.getname ()), Map.put (Emp4.getid (), Emp4.getname ()); map.put (Emp5.getid (), Emp5.getname ());        Map.Remove (Emp4.getid ()); Set <String> k=map.keyset ();iterator<string> it=k.iterator (); while (It.hasnext ()) {String str=it.next (); System.out.println (str+ "  " +map.get (str));}}}

Test results:

Java Collection Exercise--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.