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
How is java hashmap implemented?
What is sorting in java?
Can long be null in java?
What is methodological theory?
Write a program to calculate factorial in java?
I want to persist data of objects for later use. What is the best approach to do so?
What is the console in java?
what is session in java?
What is use of valueof () in java?
What are thread priorities and importance of thread priorities in java?
What is the generic class?
What is the access scope of a protected method?
What are the important features of Java 9 release?
Is string a class in java?
What is struts in java?