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 / surya chandra mohan , visakhap

small modification for first program. But that one is really excellent.i really proud Indresh_ips.


import java.util.*;
class ArrayListUnique2 {

static public ArrayList uniqueArrayList(ArrayList arrl) {
int i;
String check="";
for(int k=0;k<arrl.size();k++) {
String s=arrl.get(k).toString();


if(!check.contains(s)){
check = check+s+", ";
}else{
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 ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we declare a class as static?

1056


What do you mean by scope of variable?

853


Can we create constructor in abstract class ?

1004


What is the difference between the jdk 1.02 event model and the event-delegation model introduced with jdk 1.1?

1101


What are serialization and deserialization?

1215


What is ‘has a’’ relationship in java?

1178


What is the difference between the final method and abstract method?

1013


If an application has multiple classes in it, is it okay to have a main method in more than one class?

982


What are the features of java?

1031


What is a Transient Object?

1042


What is the difference between the reader/writer class hierarchy and the inputstream/outputstream class hierarchy in java programming?

1076


State one difference between a template class and class template.

1037


What is java full form?

982


Explain java coding standards for classes or java coding conventions for classes?

1087


What is google full form?

972