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 is multiple inheritance? Is it supported by java?
What are the library functions in java?
Can you declare a private method as static?
why would you use a synchronized block vs. Synchronized method? : Java thread
What are the legal operands of the instanceof operator?
What does the @override annotation do?
How does thread synchronization occurs inside a monitor? What levels of synchronization can you apply?
What are the features of java?
How can you add and remove nodes in jtree?
What are the 6 functions?
Why hashcode is used in java?
How big is a boolean?
what is the difference between preemptive scheduling and time slicing? : Java thread
What's the difference between an abstract class and interface in java?
How many digits is int32?