php 网站开发 视频,百度seo排名查询,京山网站设计,学电商创建Map集合#xff0c;创建Emp对象#xff0c;并将创建的Emp对象添加到集合中#xff0c;并将id为005的对象从集合中移除 创建Emp类#xff1a; package jihe;public class Emp {private String id;public String getId() {return id;}public void setId(String id) {this…创建Map集合创建Emp对象并将创建的Emp对象添加到集合中并将id为005的对象从集合中移除 创建Emp类 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;} 创建Map类并测试 package jihe;import java.util.*;public class lianxi1 {public static void main(String[] args) {MapString,String mapnew HashMap();Emp empnew Emp(001,汉堡);Emp emp1new Emp(002,薯条);Emp emp2new Emp(003,咖啡);Emp emp3new Emp(004,牛奶);Emp emp4new Emp(005,鸡翅);Emp emp5new Emp(006,鸡腿);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 kmap.keySet();IteratorString itk.iterator();while(it.hasNext()){String strit.next();System.out.println(str map.get(str));}}}测试结果 转载于:https://www.cnblogs.com/jakeasd/p/5543671.html