2012-07-24 30 views

回答

2

要確保你的陣列是Integer類型不int

Integer[] array; // Your integer array... 

Set<Integer> set = new HashSet<Integer>(); 
Collections.addAll(set, array); 
+0

是的,它的工作非常感謝你... ... - – Srinivasan 2012-07-24 12:13:05

0

試試這個代碼

public static void removeDuplicateWithOrder(ArrayList arlList) 
{ 
    Set set = new HashSet(); 
    List newList = new ArrayList(); 
    for (Iterator iter = arlList.iterator(); iter.hasNext();) { 
     Object element = iter.next(); 
     if (set.add(element)) 
     newList.add(element); 
    } 
    arlList.clear(); 
    arlList.addAll(newList); 
} 
相關問題