set 去重

来源:互联网 发布:sd卡数据无法删除不了 编辑:程序博客网 时间:2024/03/29 09:49
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());        } }}

 

 

输出:

 2
true
hell0
hello
world



原创粉丝点击