package org.hanqi.array; import java.util.*; public class Xiti2 { public static void main(String[] args) { List<String> list=new ArrayList<String>(); list.add("A"); list.add("a"); list.add("c"); list.add("C"); list.add("a"); for(String s:list) { System.out.println(s); } System.out.println("集合长度="+list.size()); System.out.println("List集合成功添加"); HashSet<String>s1=new HashSet<String>(); s1.add("A"); s1.add("a"); s1.add("c"); s1.add("C"); s1.add("a"); for(String t:s1) { System.out.println(t); } System.out.println("集合长度="+s1.size()); System.out.println("Set集合不能成功添加"); } }
package org.hanqi.array; import java.util.HashMap; import java.util.Map; public class Emp { private String key; private String value; public Emp(String key,String value) { this.key=key; this.value=value; } public String getKey() { return key; } public void setKey(String key) { this.key = key; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } public static void main(String[] args) { Map<String, String>m=new HashMap<String, String>(); Emp emp=new Emp("001","德州扒鸡"); Emp emp2=new Emp("002","北京烤鸭"); Emp emp3=new Emp("003","绝味鸭头"); Emp emp4=new Emp("004","博山酥锅"); Emp emp5=new Emp("005","武汉热干面"); Emp emp6=new Emp("006","周村烧饼"); Emp emp7=new Emp("007","淄博烧烤"); m.put(emp.getKey(), emp.getValue()); m.put(emp2.getKey(), emp2.getValue()); m.put(emp3.getKey(), emp3.getValue()); m.put(emp4.getKey(), emp4.getValue()); m.put(emp5.getKey(), emp5.getValue()); m.put(emp6.getKey(), emp6.getValue()); m.put(emp7.getKey(), emp7.getValue()); m.remove(emp5); for(String t:m.keySet()) { if(t=="005") { m.remove(emp5); } else { System.out.println(t); } } } }
时间: 2024-10-10 03:36:16