/*collection:
|--List:有序(存的顺序和取的顺序一致),元素可以重复,元素都有索引
|--ArrayList
|--linkedList
|--Set:无序,不可以重复元素,Set接口的方法和Collection中的方法一致,Set接口取出元素的方法只有迭代器Iterator
|--HashSet:底层数据结构是哈希表,哈希表这种结构其实就是对哈希值进行存储,而且每一个对象都有自己的哈希值,因为Object类中有一个HashCode方法,可以返回哈希值。
|--TreeSet*/
import java.util.*;
public class HashSetDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HashSet hs=new HashSet();
hs.add("hello");
hs.add("world");
hs.add("java");
Iterator it=hs.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
}
output: hello
java
world
转载于:https://blog.51cto.com/asalinux/641837