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 the exact difference in between Unicast and Multicast object? Where will it be used?
What is the use of string and stringbuffer?
Why we use methods in java?
how we can make a write-only class in java?
What is use of set in java?
Explain tree set and its features?
What are the string methods in java?
What are the types of sockets in java?
Differentiate between vector and array list.
What is the difference between array list and vector in java?
What is method and methodology?
Why java is call by value?
What is finalize()?
What is the final keyword?
What is token in java?