zoukankan      html  css  js  c++  java
  • 22.9

     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 }
    View Code
  • 相关阅读:
    数组列简介
    linq的使用
    StringBuilder对象
    使用类来继承接口
    设置函数库并引用
    循环语句
    cut和paste用法
    uniq用法
    shell中数组的应用
    委派
  • 原文地址:https://www.cnblogs.com/wanjiang/p/6131062.html
Copyright © 2011-2022 走看看