import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; public class HashSetDemo { public static void main(String[] args){ List tableList = new ArrayList(); tableList.add("hello"); tableList.add("hell0"); tableList.add("world"); tableList.add("world"); tableList.add(2); tableList.add(2); tableList.add(true); tableList.add(true); HashSet hs = new HashSet(tableList); //System.out.println(hs.toString()); //System.out.println(tableList); Iterator i = hs.iterator(); while(i.hasNext()){ Object temp = i.next(); System.out.println(temp.toString()); } } }
输出:
2truehell0helloworld