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
What is character in data type?
What do you mean by formatting?
What is listnode in java?
When is the finally clause of a try-catch-finally statement executed?
Why there are some null interface in java? What does it mean?
What is Garbage Collection in Java
What is an escape character in java?
How many tetrahedral voids are there in bcc?
List some features of the abstract class.
If goto and const is reserve words than why it is not work in java?
What is an infinite loop?
What is hasnext in java?
What is the difference between error and an exception?
What is the difference between procedural and object-oriented programs?
Can a class declared as private be accessed outside it’s package?