62,615
社区成员
发帖
与我相关
我的任务
分享
import java.util.*;
class TestSet
{
public static void main(String[] args)
{
Integer[] nums = { 5, 5, 6, 6, 6, 8, 8, 7, 11, 12, 12 };
HashSet hset = new HashSet(Arrays.asList(nums));
Iterator i = hset.iterator();
while(i.hasNext()){
System.out.println(i.next());
}
}
}
public static void main(String[] args) {
String[] s = {"1","10","15","14","111","133","12","13","1","13"};
List<String> l = new ArrayList<String>();
for(String a:s){
if(!l.contains(a)){
l.add(a);
}
}
System.out.println(l);
}
Integer[] nums = { 5, 6, 6, 6, 8, 8, 7 };
Set<Integer> numSet = new LinkedHashSet<Integer>(Arrays.asList(nums));
System.out.println(numSet);
public <T> List<T> removeSameItem(List<T> list) {
List<T> difList = new ArrayList<T>();
for(T t : list){
if(t != null && !difList.contains(t)){
difList.add(t);
}
}
return difList;
}