How to declare unique ArrayList ?

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


Please Help Members By Posting Answers For Below Questions

What is package private scope in java?

535


Explain methods specific to list interface?

557


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???

1673


Which containers use a flowlayout as their default layout in java programming?

514


What does a za z0 9 mean?

564






What are the two parts of a conditional statement?

518


design an lru cache in java?

546


What is the purpose of the finalize() method?

714


What is qms certification?

522


Describe the syntax of multiple inheritance? When do we use such an inheritance?

588


What is the memory leak in java?

527


Does isempty check for null?

561


What is the difference between method overriding and overloading?

583


What is externalizable interface?

583


Explain about varargs in java?

584