Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Can an interface be final?

972


Can you extend singleton class?

1034


Explain the difference between collection api and stream api in java8?

910


Explain heap sort?

1042


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)

1755


How many types of classes are there in java?

996


what is the purpose of the wait(), notify(), and notifyall() methods? : Java thread

927


What is a condition in programming?

958


What exceptions occur during serialization?

1033


Can we create our own wrapper class in java?

908


What if static is removed from main method?

1011


What do you mean by flow of struts?

1224


Explain what access modifiers can be used for variables?

1005


What is bubble sorting in java?

992


What is a locale?

1094