I have a Arraylist object, it has duplecate values also. Now
question is i want delete duplecate data in that objet with
out using Set?
Answer Posted / athira
package com.modon;
import java.util.ArrayList;
public class MyArrayList {
public static void main(String[] args) {
ArrayList<Object> dupList=new ArrayList<Object>();
ArrayList<Object> resultList=new ArrayList<Object>();
dupList.add(1);
dupList.add(2);
dupList.add(3);
dupList.add("D");
dupList.add("A");
dupList.add("F");
dupList.add("A");
dupList.add("A");
dupList.add(1.5);
dupList.add(1.50);
dupList.add(new String("A"));
dupList.add(new Integer(3));
for(Object s:dupList){
if(!resultList.contains(s))
resultList.add(s);
}
System.out.println("dupList: "+dupList.size());
System.out.println("resultList: "+resultList.size());
}
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Write a method that will remove given character from the string?
Can we write method inside a method in java?
What is one third plus one third as a fraction?
What two classes are used to read data only?
What is a website container?
What is java’s garbage collected heap?
What is the structure of java?
Explain about doubly linked list
What is a default method?
What is the use of parseint in java?
Explain the importance of finalize() method.
Will the jvm load the package twice at runtime?
How many types of gc are there in java?
Is alive method in java?
Explain the key functions of data binding?