Answer Posted / sudhakar
I have modified the above program. And made esay the
process.
import java.util.ArrayList;
public class UniqueArrayListValues {
static ArrayList assignValues() {
ArrayList a1 = new ArrayList();
a1.add("A");
a1.add("B");
a1.add("C");
a1.add("27");
a1.add("A");
a1.add("B");
a1.add("C");
a1.add("27");
a1.add("A");
a1.add("B");
a1.add("C");
a1.add("27");
return a1;
}
static ArrayList applyUniqueKey(ArrayList a1) {
ArrayList a2 = new ArrayList();
for (int i = 0; i < a1.size(); i++) {
if (!a2.contains(a1.get(i))) {
a2.add(a1.get(i));
}
}
return a2;
}
public static void main(String args[]) {
ArrayList beforeUniqueKey = assignValues();
System.out.println("Before applying Unique
Key:" + beforeUniqueKey);
ArrayList afterUniqueKey = applyUniqueKey
(beforeUniqueKey);
System.out.println("Afrer applying Unique
Key:" + afterUniqueKey);
}
}
Is This Answer Correct ? | 5 Yes | 2 No |
Post New Answer View All Answers
What is empty list in java?
What are the restrictions imposed by a Security Manager on Applets?.
What are the different conditional statements?
What is callable java?
What is the purpose of void?
Why is java called the platform independent programming language?
What does s mean in regex?
Why java is secure? Explain.
Why can't we use static class instead of singleton?
Name and explain the types of ways which are used to pass arguments in any function in java.
What is int short for?
Can we call the run() method instead of start()?
Why vector is used in java?
What is method in java ?
What is overloading and overriding in java?