I am printing items from an ArrayList with this code:
for(int i2 = 0; i2 < a.size(); i2++)
{
word2 = a.get(i2);
for(int j2 = 0; j2 < a.size(); j2++)
{
if(word2.equals(a.get(j2)))
{
counter++;
}
}
if(counter!=0)
{
System.out.println(word2 + " : " + counter);
}
counter = 0;
}
When I print I don't want to print out the duplicates. As it is now, it will print
Alphabet : 3
Alright : 3
Apple : 3
Alphabet : 3
Alright : 3
Apple : 3
Alphabet : 3
Alright : 3
Apple : 3
I only want it to print
Alphabet : 3
Alright : 3
Apple : 3
How do I make it not print the duplicates? I have to use ArrayList for the assignment
Setinstead of aListMultimapMultisetwould be more appropriate (theMultimapwould require some arbitrary value objects), but same idea. The words could be inserted into, e.g., Guava'sMultiset, thencount()will return the word count given a word. You should post an example as an answer, it would be another nice clean approach.