java三种方法去重复

String[] str = {"33","55","55","22","22","22"}; //第一种  字符串数组去掉重复
		    List list = new ArrayList();    
		    for (int i=0; i
		    Integer[] nums = { 33, 20, 20, 33, 6, 8, 8, 7, 11, 12, 12 };  // 第二种  整形数组去掉重复
		    TreeSet hset = new TreeSet(Arrays.asList(nums));
		    Iterator i = hset.iterator();
		    while(i.hasNext()){
		        System.out.print(i.next()+" ");
		    } 
		    

		    String test = "100,120,166,1555,120,150,100";  // 第三种  字符串去掉重复
		    String[] str=test.split(",");
		    List list=new ArrayList();
		    for (int i = 0; i < str.length; i++) {
				if(!list.contains(str[i])){
					list.add(str[i]);
				}
			}
		    for (int i = 0; i < list.size(); i++)
	            System.out.print(list.get(i)+" ");
			}

你可能感兴趣的:(java三种方法去重复)