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
What are the advantages of compiled language?
What is final method in java?
What are pass by reference and pass by value?
What is the functionability stubs and skeletons?
What is the difference between super class & sub class?
What is the use of StringTokenizer class?
Difference between notify() method and notifyall() method in java?
What is the generic class?
why are wait(), notify() and notifyall() methods defined in the object class? : Java thread
Can sleep() method causes another thread to sleep?
Is there any difference between synchronized methods and synchronized statements?
What is null data type?
What is arraylist e in java?
Which class contains a method: cloneable or object?
What steps are taken when the OS shifts from one-thread execution to another?