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
Variable of the boolean type is automatically initialized as?
How can you write a loop indefinitely in java programming?
What is the functionality of the stub?
Is array an object in java?
Can we modify the throws clause of the superclass method while overriding it in the subclass?
Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example
What does java se mean?
What defines function?
What is balanced tree in java?
Define how does a try statement determine which catch clause should be used to handle an exception?
How do you compare characters in java?
Describe what a thread-local variable is in java?
Can you inherit a constructor java?
What are the java ide’s?
Can we use return in constructor?