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...

How to eliminate duplicates from an array?

Answer Posted / elango boopathy

package com.sample.pack;

import java.util.ArrayList;
import java.util.List;

public class Duplicates {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int k = 1;
String[] str = { "abc", "123", "tyu", "xyz", "123", "m",
"abc", "abc" };
boolean isDuplicate = false;
List<String> list = new ArrayList<String>();

for (int i = 0; i < str.length; i++) {
for (int j = k; j < str.length; j++) {
if (str[i].equals(str[j].toString())) {
isDuplicate = true;
}
}
k = k + 1;
if(isDuplicate == false){
list.add(str[i]);

}
isDuplicate = false;
}
Object[] afterDuplicate = list.toArray();
for(int i=0; i<afterDuplicate.length; i++){
System.out.println(afterDuplicate[i]);
}
}

}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of flag?

1021


What are the difference between string, string builder, and string buffer in java?

1073


Program to Find the second largest element in an array.

1114


What are some examples of variable costs?

895


Can we override compareto method?

899


What is polymorphism and what are the types of it?

943


What is the exception hierarchy in java?

914


What is difference between float and double?

914


What is a byte string?

1055


What are the three parts of a lambda expression?

947


What is arrays aslist in java?

924


What is the Scope of Static Variable?

1165


Is void a wrapper class?

886


How do you clear an arraylist in java?

937


Assume a thread has lock on it, calling sleep() method on that thread will release the lock?

1046