关于HashSet Container
来源:互联网 发布:淘宝卖家邮费怎么便宜 编辑:程序博客网 时间:2024/06/05 20:43
package container;
import java.util.Collection;
import java.util.HashSet;
public class Container {
public static void main(String[] args) {
Collection c = new HashSet();
c.add("Hello");
c.add(new Integer(100));
c.add(new Name("Ming","li"));
System.out.println(c);
c.remove("Hello");
System.out.println(c);
c.remove(new Integer(100));
System.out.println(c);
c.remove(new Name("Ming","li")); //不会移除对象,没有重写equals()无法判断这个对象是否是c中已存在的对象。没有重写equals()时
System.out.println(c);
}
}
class Name{
private String firstname;
private String lastname;
public Name (String f,String l){
firstname=f;
lastname = l;
}
public String toString (){
return firstname+lastname;
}
import java.util.Collection;
import java.util.HashSet;
public class Container {
public static void main(String[] args) {
Collection c = new HashSet();
c.add("Hello");
c.add(new Integer(100));
c.add(new Name("Ming","li"));
System.out.println(c);
c.remove("Hello");
System.out.println(c);
c.remove(new Integer(100));
System.out.println(c);
c.remove(new Name("Ming","li")); //不会移除对象,没有重写equals()无法判断这个对象是否是c中已存在的对象。没有重写equals()时
System.out.println(c);
}
}
class Name{
private String firstname;
private String lastname;
public Name (String f,String l){
firstname=f;
lastname = l;
}
public String toString (){
return firstname+lastname;
}
}
0 0
- 关于HashSet Container
- 关于,hashCode与hashSet
- 关于HashSet与HashMap
- 关于HashMap与HashSet;
- 关于 类hashSet<E> hashSet 遍历 hashSet<String>和hashSet<Person>
- 关于HashSet中的无序问题
- HashSet
- Hashset
- HashSet
- HashSet
- HashSet
- HashSet
- HashSet
- HashSet
- HashSet
- HashSet
- HashSet
- HashSet
- C语言笔记之关键字(二)
- JavaScript创建对象的三种方法
- hibernate 面试题
- 通过反射动态获取资源id
- win10下安装Mysql5.7
- 关于HashSet Container
- 数学
- 使用IntelliJ IDEA开发SpringMVC网站(一)开发环境
- [LeetCode]199. Binary Tree Right Side View
- hive 实例
- Programming in Objective-C 学习笔记04——变量和数据类型
- 解决init: sys_prop: permission denied uid:1003 name:service.bootanim.exit问题
- mysql 错误集
- LCP Array