import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = { 2, 3, 5, 4, 1, 2, 3, 4, 6 };
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < a.length; i++) {
if (!list.contains(a[i])) {
list.add(a[i]);
}
}
System.out.println("去除重复后的list集合" + list);
}
}
Integer[] nums = { 5, 5, 6, 6, 6, 8, 8, 7, 11, 12, 12 };
// HashSet hset = new HashSet(Arrays.asList(nums));
TreeSet<Integer> hset = new TreeSet<Integer>(Arrays.asList(nums));
Iterator i = hset.iterator();
while(i.hasNext()){
System.out.println(i.next());
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30180323/viewspace-2149468/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/30180323/viewspace-2149468/