1 import java.util.HashMap; 2 import java.util.Map; 3 import java.util.Set; 4 import java.util.StringTokenizer; 5 import java.util.TreeMap; 6 7 public class S22_9 { 8 9 public static void main(String[] args) { 10 // TODO Auto-generated method stub 11 String myText = "today is a good day! I am happy to be a man in the world." + 12 "since the day I relize I am good to study by myself?"; 13 14 StringTokenizer strToken = new StringTokenizer(myText," .?!;,"); 15 HashMap<String,Integer> myHashMap = new HashMap<String,Integer>(); 16 while(strToken.hasMoreTokens()){ 17 String tempStr = strToken.nextToken().toLowerCase(); 18 if(myHashMap.get(tempStr) == null) 19 myHashMap.put(tempStr, 1); 20 else { 21 int value = myHashMap.get(tempStr).intValue(); 22 value++; 23 myHashMap.put(tempStr, value); 24 } 25 } 26 27 Set entrySet = new TreeMap(myHashMap).entrySet(); 28 29 for(Object myHash:entrySet) 30 { 31 System.out.println(myHash); 32 } 33 } 34 35 }