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

Why Do I Get A "permission Denied" Error After Downloading The .jnlp Java Launcher For The Vkvm?

871


What are three advantages of using functions?

773


Name few java.lang classes introduced with java 8 ?

769


What is the difference between inner class and nested class?

784


What is field name?

789


How do you escape sequences in java?

826


What do you mean by light weight and heavy weight components?

773


What is the locale class in java programming?

769


How can you say java is object oriented?

843


What do you mean by constant time complexity?

848


How can we create an immutable class in java?

828


What is meant by class?

786


Why does the integer quotient -0/3 yield 0, but the double quotient -0.0/3.0 yields – 0.0?

838


Can you call a method in a method?

785


how we can create packages in java?

730