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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is multiple inheritance? Is it supported by java?

914


What are the library functions in java?

976


Can you declare a private method as static?

1093


why would you use a synchronized block vs. Synchronized method? : Java thread

898


What are the legal operands of the instanceof operator?

953


What does the @override annotation do?

956


How does thread synchronization occurs inside a monitor? What levels of synchronization can you apply?

914


What are the features of java?

1001


How can you add and remove nodes in jtree?

971


What are the 6 functions?

905


Why hashcode is used in java?

915


How big is a boolean?

981


what is the difference between preemptive scheduling and time slicing? : Java thread

973


What's the difference between an abstract class and interface in java?

973


How many digits is int32?

925