去掉数组中相同的值

//去掉数组中相同的项
		//我们知道,数组的项是可以重复的,有时候我们需要去掉数组中重复的项,怎么办?
		//我们也知道,HashSet里面是没有重复的项的,我们可不可以将数组转化为HashSet,然后再转化?    
		      
		       String[] strs1 = new String[]{"8","1","1","3","3","2","11","7"};
		       HashSet set = new HashSet();
		       set.addAll(Arrays.asList(strs1));
		       //Arrays.asList将数组转List,addAl将Collection转化为HashSet
		       String[] strs2 = (String[])set.toArray(new String[0]);
		       for(int i=0;i<strs2.length;i++){
		            System.out.println(strs2[i]);
		       }

你可能感兴趣的:(郏高阳,去掉数组中相同的值)