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
Explain creating threads by implementing runnable class?
What is the difference between heap memory and stack memory?
What is type inference in java8?
Why do we declare a class static?
What is final int?
What are drawbacks of singleton class?
What do you mean by multithreaded program?
When parseint method can be used?
Can we clone singleton class in java?
What are implicit objects in java?
What are the two parts of a conditional statement?
What happens to the Exception object after handling an exception?
What is identifier with example?
Why should I use abstract class?
Explain the difference between arraylist and linkedlist in java?