Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Discuss different types of errors that generally occur while programming.

980


What is the purpose of the runtime class in java programming?

1010


Why wait and notify methods are declared in object class?

974


Explain different types of wrapper classes in java?

953


What is the difference between error and an exception?

1059


Why is java not 100% pure oops?

1078


Name component subclasses that support painting in java programming?

1012


Can we override private method in java?

1043


What do you understand by java?

922


What is difference between equal and == in java?

904


What are daemon Threads in java?

1127


How java enabled high performance?

1001


Why local variables are stored in stack?

920


What is boolean query?

918


What is java dot?

885