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 / sreenivas

Hi,
I hope the answer I am providing is the easiest one among
all others

import java.util.ArrayList;
import java.util.Iterator;

public class ArrayListDemo
{
public static void main(String[] args)
{
ArrayList containsDuplicate = new ArrayList
();

containsDuplicate.add("A");
containsDuplicate.add("B");
containsDuplicate.add("C");
containsDuplicate.add("D");
containsDuplicate.add("A");
containsDuplicate.add("B");
containsDuplicate.add("C");
containsDuplicate.add("A");

ArrayList noDuplicate = new ArrayList
(containsDuplicate);
ArrayList fresh = new ArrayList();

System.out.println("Hello World!!!!!!!!
with duplicates " + containsDuplicate.size());
System.out.println("Hello World!!!!!!!!
with duplicates " + noDuplicate.size());
for(int i =0;i<containsDuplicate.size();i++)
{
String outerObject = (String)
containsDuplicate.get(i);
int count = 0;
for(int j=0;j<noDuplicate.size
();j++)
{
String innerObject =
(String) noDuplicate.get(j);
if(outerObject.equals
(innerObject))
{
if((count == 0))
{
count++;
// fresh.add
(outerObject);
}
else
{

noDuplicate.remove(j);

}
}

}
}

for(int i=0; i< noDuplicate.size();i++)
{
System.out.println("Each
Element :::::::: " + noDuplicate.get(i));
}
}
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you achieve polymorphism in java?

933


How do you include a string in java?

927


What are advantages of exception handling in java?

974


Explain the difference between runnable and callable interface in java?

1000


Why is singleton not thread safe?

1008


Difference between string, string builder, and string buffer?

1020


What are the types of methods in java?

1034


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

909


Explain about OOPS concepts and fundamentals.

996


What is the java reflection api? Why it’s so important to have?

923


What is the integer of 16?

928


Why does java have two ways to create child threads? Which way is better?

984


Why is method overloading not possible by changing the return type in java?

942


How is string stored in java?

1004


is there a separate stack for each thread in java? : Java thread

928