In Java is there an object like a “Set” that can contain only unique string values, but also contain a count on the number of occurrences of the string value?
The idea is simple
With a data set ala…
A
B
B
C
C
C
I’d like to add each line of text to a Set-like object. Each time that a non-unique text is added to the set I’d like to also have a numeric value associated with the set to display how many times it was added. So if I ran it on the above data set the output would be something like:
A : 1
B : 2
C : 3
any ideas?
Map<String, Integer>would be the best bet, to put in words what you want to do is to Map the amount of occurrences of a string. Basically have something like this: