Answer Posted / indresh_ips
Hey, Here is the program of Unique ArrayList.........
Just Run It........
import java.util.*;
class ArrayListUnique {
static public ArrayList uniqueArrayList(ArrayList arrl) {
int i;
for(int k=0;k<arrl.size();k++) {
Object s=arrl.get(k);
i=Collections.frequency(arrl,s);
for(int j=1;j<i;j++) {
arrl.remove(s);
}
}
return arrl;
}
public static void main (String[] args) {
ArrayList al= new ArrayList();
al.add("A");
al.add("A");
al.add("B");
al.add("C");
al.add("B");
al.add("A");
al.add("D");
al.add("D");
al.add("D");
al.add("D");
al.add("A");
al.add("B");
al.add("F");
al.add("G");
al.add("G");
al.add(10);
al.add(5);
al.add(10);
al.add(5);
System.out.println ("Before declaring unique:"+al);
ArrayList a=ArrayListUnique.uniqueArrayList(al);
System.out.println ("after declaring unique: "+a);
}
}
| Is This Answer Correct ? | 7 Yes | 2 No |
Post New Answer View All Answers
Difference between character constant and string constant in java ?
Which types of exceptions are caught at compile time?
What is static variable with example?
What is the difference between && and & in java?
What do you mean by buffering?
Differentiate storage classes on the basis of their scope?
What are the two parts of a conditional statement?
What is the difference between serializable and externalizable interfaces?
What is the exact difference in between unicast and multicast object? Where we will use?
Can singleton class be cloned?
How do you find the maximum number from an array without comparing and sorting?
What is java util?
Is it possible to override the main method?
What is bom encoding?
What is bytecode verifier?