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


Please Help Members By Posting Answers For Below Questions

What are the differences between include directive and include action?

548


What are the new features in java 8?

574


State the main difference between c++ and java?

594


When a thread is executing a synchronized method , then is it possible for the same thread to access other synchronized methods of an object ?

613


What are mutable classes?

526






Should a main method be compulsorily declared in all java classes?

536


What is a method vs function?

564


Can we overload final method in java?

556


When do we use hashset over treeset?

538


What is a parameter example?

532


What ide should I use for java?

494


What is an example of declaration?

528


What exactly is a .class file?

580


Why generics are used in java?

554


1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED OBJECT DIRECTLY TO ACCESS THE DATA MEMBER AND MEMBER FUNCTION OF THAT RESPECTIVE CLASS?WHAT IS THE MAIN FUNCTION OF "REFERENCE VARIABLE" HERE?

3793