01.---------------------- <a href="http://www.itheima.com"target="blank">ASP.Net+Unity开发</a>、<a href="http://www.itheima.com"target="blank">.Net培训</a>、期待与您交流! ----------------------
package heimaLog;
import java.util.*;
/*
* set集合特点是元素无序,(存入和取出的顺序不一定一致)元素不可以重复。
* set集合的功能和Collection功能一致
* set常见子类
* HashSet :底层数据结构式哈希表
* TreeSet :底层数据是二叉树
*
* HashSet集合在存储数据时先判断地址是否相同然后判断是否是同一对象;
* */
class Demo{
public int hashCode(){
return 60;
}
}
public class HashSetDemo {
public static void sop(Object obj){
System.out.println(obj);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
// Demo d = new Demo();
// Demo d1= new Demo();
// sop(d);
//sop(d1);
HashSet hs =new HashSet();
hs.add("JAVA001");
hs.add("JAVA001");
hs.add("JAVA003");
hs.add("JAVA004");
Iterator it = hs.iterator();
while(it.hasNext()){
sop(it.next());
}
}
}
---------------------- <a href="http://www.itheima.com"target="blank">ASP.Net+Unity开发</a>、<a href="http://www.itheima.com"target="blank">.Net培训</a>、期待与您交流! ----------------------