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
What is object data type?
Can a main method be overloaded?
What is jar?
how to create multithreaded program? : Java thread
Explain the access modifiers for a class, method and variables?
What does this () mean in java?
Can singleton class be cloned?
Which types of exceptions are caught at compile time?
which one is more efficient int x; 1. if(x==null) 2.if(null==x) state which one either 1 or 2?
Is java 1.7 the same as java 7?
What are the advantages of inner classes?
Explain about strings in java?
Which category the java thread do fall in?
what is heap memory?
What is the difference between integer parseint and integer valueof?