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
Can an interface be final?
Can you extend singleton class?
Explain the difference between collection api and stream api in java8?
Explain heap sort?
Say you want to store the information about a number of pets in an array. Typical information that you could store for each pet (where relevant) would be • Breed of animal • Animal's name • Its birth date • Its sex • Whether it has been sterilised or not • When it is due for its next inoculation • When it last had its wings clipped For each type of pet (eg. dog, cat or bird) you would typically define a class to hold the relevant data. Note: You do not need to implement these classes. Just answer the following questions. 3.1.1 What would be the advantage of creating a superclass (eg. Pet) and declaring an array of Pet objects over simply using an array of Objects, storing each of the instances of the different pet classes (eg. Dog, Cat or Bird) in it? 3.1.2 Would you define Pet as a class or as an interface? Why? (2) (2)
How many types of classes are there in java?
what is the purpose of the wait(), notify(), and notifyall() methods? : Java thread
What is a condition in programming?
What exceptions occur during serialization?
Can we create our own wrapper class in java?
What if static is removed from main method?
What do you mean by flow of struts?
Explain what access modifiers can be used for variables?
What is bubble sorting in java?
What is a locale?