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 are the differences between include directive and include action?
What are the new features in java 8?
State the main difference between c++ and java?
When a thread is executing a synchronized method , then is it possible for the same thread to access other synchronized methods of an object ?
What are mutable classes?
Should a main method be compulsorily declared in all java classes?
What is a method vs function?
Can we overload final method in java?
When do we use hashset over treeset?
What is a parameter example?
What ide should I use for java?
What is an example of declaration?
What exactly is a .class file?
Why generics are used in java?
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?