final char [] CHARS = DATA;
// We'll use a char -> int map for counting. If you know the likely
// number of distinct key values in the map, pass it to the constructor
// to avoid resizing of the map.
final CharIntOpenHashMap counts = new CharIntOpenHashMap(256);
// Loop over the characters and increase their corresponding entries in the map
for (int i = 0; i < CHARS.length; i++)
{
// Adds 1 if the entry exists, sets 1 if the entry does not exist
counts.putOrAdd(CHARS[i], 1, 1);
}
// [[[end:character-counting]]]
final TotalCounter counter = new TotalCounter();
counts.forEach(counter);
Assert.assertEquals(counter.total, DATA.length);
}