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
Can we declare a class as static?
What do you mean by scope of variable?
Can we create constructor in abstract class ?
What is the difference between the jdk 1.02 event model and the event-delegation model introduced with jdk 1.1?
What are serialization and deserialization?
What is ‘has a’’ relationship in java?
What is the difference between the final method and abstract method?
If an application has multiple classes in it, is it okay to have a main method in more than one class?
What are the features of java?
What is a Transient Object?
What is the difference between the reader/writer class hierarchy and the inputstream/outputstream class hierarchy in java programming?
State one difference between a template class and class template.
What is java full form?
Explain java coding standards for classes or java coding conventions for classes?
What is google full form?