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
Is it possible to compare various strings with the help of == operator?
Can we override singleton class?
Can we declare array without size in java?
why we use merge option in hybernate pls give a ex snippet
What is a function in java?
Give an example of call be reference significance.
Is object a data type?
What is an example of a boolean?
what are the states associated in the thread? : Java thread
What does %4d mean in java?
Why deletion in linkedlist is fast than arraylist?
What is the synchronized method modifier?
What does indexof mean?
how to deploy apache tomcat server to weblogic server in java
What is api in java?