62,614
社区成员
发帖
与我相关
我的任务
分享
String a = new String("a");
String b = new String("b");
String a2 = new String("a");
Collection col = new HashSet();
col.add(a);
col.add(b);
// col.add(a2);
a = "";
col.remove(a);
// col.remove(a2);
System.out.println(col);
String a = new String("a");
String b = new String("b");
String a2 = new String("a");
Collection col = new HashSet();
col.add(a);
col.add(b);/*这个时候col对象中包含了两个String元素"a","b"*/
// col.add(a2);
a = ""; /*更改a引用类型指向的对象*/
col.remove(a);/*从col中移除a引用所指向的对象,因为col中不包含"",所以remove失败*/
// col.remove(a2);
System.out.println(col);/*结果[b,a]*/
System.out.println( col.remove(a));
//false