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 the difference between yielding and sleeping in java programming?
What is time complexity algorithm?
What is pass by value?
Can a static member function access member variable of an object?
Explain the difference between transient and volatile in java?
What is the difference between throw and throws in java?
What is empty list in java?
Are strings immutable in java?
What is a boolean flag in java?
What is the advantage of preparedstatement over statement?
Define nashorn in java8.
Can you tell me range of byte?
What is the Scope of Static Variable?
Should you use singleton pattern?
What is a heavyweight component?