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 get () in java?
What is pre increment and post increment in java?
Tell me about different OOPS concepts.
What are the types of java?
What is module in project?
When a thread is executing a synchronized method , then is it possible for the same thread to access other synchronized methods of an object ?
Is treeset sorted in java?
Why string is a class?
How is abstraction implemented in java ?
Can we define private and protected modifiers for variables in interfaces?
What is predicate in java?
What is definition and declaration?
What variables are stored in stack?
What is internal iteration in java se 8?
What is your platform?s default character encoding and how to know this?