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 an objects lock and which objects have locks? : Java thread
What is java regex?
What are daemon Threads in java?
What are selection structures?
Why java strings are immutable in nature?
Explain the polymorphism principle?
How do you define a singleton class?
What is derived datatype?
What is array size in java?
What do you understand by java virtual machine?
How many functional interfaces does java 8 have?
What is broken and continue statement?
what is comparable and comparator interface?
What is identifier give example?
What is methodological theory?