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
What are the wrapped, classes?
Why do we need wrapper classes?
What is "this" keyword in java? Explain
What is the simpletimezone class in java programming?
What is module with example?
Write a program to print 15 random numbers using foreach of java 8?
Can we write multiple catch blocks under single try block?
what state does a thread enter when it terminates its processing? : Java thread
Explain when classnotfoundexception will be raised ?
Difference between stack and queue?
Name four container classes.
Can this keyword be used to refer static members?
Explain abstract class in java?
What is encapsulation in java?
Why can't we make a class private in java?