ArrayList
- 底层由数组实现
- 元素有序且可以重复
- 可以动态增长,以满足应用程序的需求
- 元素值可以为null
HashSet
- 元素无序并且不可以重复
- 只允许一个null元素
HashMap
- 键不能重复
- 允许使用null值和null键
- HashMap中的Entry对象是无序排列的
Iterator(迭代器)
Iterator接口以统一的方式对各种集合元素进行遍历
Iterator<String> it=set.iterator();
while(it.hasNext()){
System.out.print(it.next()+" ";
}
HashCode()
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + age;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((species = = null) ? 0 : species.hashCode());
return result;
}
equals()
public boolean equals(Object obj) {
if (this == obj)
return true;
if(obj.getClass()==Cat.class){
Cat cat=(Cat)obj;
return cat.getName().equals(name)&&(cat.getAge()==age)&&cat.getSpecies().equals(species);
}
return false;
}