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
Does collectionutils isempty check for null?
What does \ mean in regex?
What is passing by reference in java?
Why java is made?
What is the difference between multiple processes and multiple threads?
What happens when a thread cannot acquire a lock on an object in java programming?
Is heap stored in ram?
what is predefined function in java?
Explain about anonymous inner classes ?
Why declare Main() inside the class in java ?
What is the difference between serializable and externalizable interfaces?
What are the important features of Java 8 release?
What is variable and example?
Why singleton class is used in java?
What are the drawbacks of reflection?