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 count occurrences of each duplicate element in a list
{a,b,d,c,a,b} ?

Thanks in Advance

Answers were Sorted based on User's Feedback



How to count occurrences of each duplicate element in a list {a,b,d,c,a,b} ? Thanks in Advance..

Answer / lal ajith kumara

Since java.Util.Set is not allowing duplicates u can use it

String[] letters = {"a", "b", "b", "c" ,"a", "d","a"};
Set duplicateTester = new HashSet<String>();
for(int i = 0; i<letters.length;i++){
if(true == duplicateTester.add(letters[i])){
System.out.println("true>>"+letters[i]);

}else{
System.out.println("false>>"+letters[i]);
}

}

Is This Answer Correct ?    7 Yes 1 No

How to count occurrences of each duplicate element in a list {a,b,d,c,a,b} ? Thanks in Advance..

Answer / pratiksha

import java.util.*;
class alpha
{
String let;
public alpha(String l)
{
this.let=l;
}
}

public class Duplicateletters
{
public static void main(String []args)
{
int i=0;
String[] letters = {"a", "b", "b", "c" ,"a", "d","a"};
ArrayList<alpha> a = new ArrayList<alpha>();
for(i=0;i<letters.length;i++)
{
a.add(new alpha(letters[i]));
}
String let1=null;
Iterator<alpha> i1 = a.iterator();
while(i1.hasNext())
{
alpha a1 = i1.next();
let1=a1.let;
}
int j=0;
Iterator<alpha> i2 = a.iterator();
while(i2.hasNext())
{

alpha a2 = i2.next();
if(let1==a2.let)
{
j=j+1;
}
}
System.out.println(j);

}
}

Is This Answer Correct ?    3 Yes 1 No

Post New Answer

More Core Java Interview Questions

What is namespace in java?

0 Answers  


If there is no implementation of MARKER INTERFACE in java. Then how compiler come to know about specification.

2 Answers  


How do you sort an array in java?

0 Answers  


How can you write a loop indefinitely in java programming?

0 Answers  


What is the difference between the synchronized() & static synchronized()?

2 Answers   HP, SparkTG,


List implementations of list interface?

0 Answers  


What are the differences between string, stringbuffer and stringbuilder?

0 Answers  


What is the difference between a constructor and a method?

0 Answers  


How to reverse a string in java?

0 Answers  


What is percentage in java?

0 Answers  


What is the use of a copy constructor?

0 Answers   Flextronics,


What is singleton class?

16 Answers   3i Infotech, 7 Seas, ABC, Amdocs, Cap Gemini, Oracle, Persistent, TCS, Techforza,


Categories