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 is package private scope in java?
Explain methods specific to list interface?
when a request is generated from apache tomcat 5.5 and goes to oracle 10g or mysql,,, how the oracle or mysql reads the request as apache is a web server and oracle 10g is application server? when the oracle 10g provides response, how the apche tomcat reads it???
Which containers use a flowlayout as their default layout in java programming?
What does a za z0 9 mean?
What are the two parts of a conditional statement?
design an lru cache in java?
What is the purpose of the finalize() method?
What is qms certification?
Describe the syntax of multiple inheritance? When do we use such an inheritance?
What is the memory leak in java?
Does isempty check for null?
What is the difference between method overriding and overloading?
What is externalizable interface?
Explain about varargs in java?