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
Why stringbuilder is not thread safe?
What is the main method java?
What is a method type?
What is passing value java?
What is difference between == and === in js?
What string is utf8?
Why does java have different data types for integers and floating-point values?
What is map java?
Can a class have a static inner class?
what is singleton class in java?
How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters?
What do you mean by local variable and instance variable?
What is a condition in java?
What is a static class in java?
Is a class subclass of itself?