Posted By:
Michael_Wax
Posted On:
Tuesday, April 10, 2001 05:07 PM
Use a HashMap to maintain a count by character in the text.
// 'body' is a String containing the text you have read in
HashMap map = new HashMap(26);
char current;
for (int i=0; i current = temp.charAt(i);
//skip if not a letter
if (!Character.isLetter(current)) continue;
//'a' and 'A' are the same letter
String temp = String.valueOf(current)toUpperCase();
if (map.get(temp) != null) {
int count = ((Integer) map.getTemp()).intValue();
map.put(temp, new Integer(count++));
}
else map.put(temp, new Integer(1));
}