Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


boostr.in questions - Question:ArrayList Duplicate Removal


 

public static void deleteDuplicates(ArrayList list){
    ArrayList newList = new ArrayList();
    HashSet set = new HashSet();
 
    for(int i = 0; i < list.size(); i++){
        set.add(list.get(i));
    }
 
    newList.addAll(set);
    return newList;
}
My input for this is the following:
 
1, 2, 2, 3, 4, 3, 1, 5, 5, 4, 1, 4, 5
And the output I'm getting is:
 
3, 2, 4, 1, 5
Can anyone explain why this is out of order?

asked Sep 13, 2013 in Java Interview Questions by rajesh
retagged Sep 12, 2013 by rajesh
0 votes
14 views



Related Hot Questions



Government Jobs Opening


...