激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術|正則表達式|

服務器之家 - 編程語言 - JAVA教程 - java統計字符串單詞個數的方法解析

java統計字符串單詞個數的方法解析

2020-07-21 12:30littleFatty JAVA教程

在一些項目中可能需要對一段字符串中的單詞進行統計,本文在這里分享了一個簡單的demo,有需要的朋友可以拿去看一下

在一些項目中可能需要對一段字符串中的單詞進行統計,我在這里寫了一個簡單的demo,有需要的同學可以拿去看一下。

不說廢話了直接貼代碼:

實現代碼:

java" id="highlighter_561959">
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
   * 統計各個單詞出現的次數
   * @param text
   */
  public static void findEnglishNum(String text){
   //找出所有的單詞
   String[] array = {".", " ", "?", "!"};
   for (int i = 0; i < array.length; i++) {
    text = text.replace(array[i],",");
   }
   String[] textArray = text.split(",");
   //遍歷 記錄
   Map<String, Integer> map = new HashMap<String, Integer>();
   for (int i = 0; i < textArray.length; i++) {
    String key = textArray[i];
    //轉為小寫
    String key_l = key.toLowerCase();
    if(!"".equals(key_l)){
     Integer num = map.get(key_l);
     if(num == null || num == 0){
      map.put(key_l, 1);
     }else if(num > 0){
      map.put(key_l, num+1);
     }
    }
   }
   //輸出到控制臺
   System.out.println("各個單詞出現的頻率為:");
   Iterator<String> iter = map.keySet().iterator();
   while(iter.hasNext()){
    String key = iter.next();
    Integer num = map.get(key);
    System.out.println(key + "\n\t\t" + num + "次\n-------------------");
   }
  }

測試代碼:

?
1
2
3
public static void main(String[] args) {
   String text = "Welcome welcome to ADempiere, a commons-based peer-production of Open Source ERP Applications. This Wiki is for the global community to contribute and share know-how and domain expertise. We hope you can find as much open information and participate in making it most usable for everyone. This project has a bazaar of Citizens with a Community Council Team which work in theFunctional Team and Technical Team along the Software Development Procedure supported and funded by the foundation ADempiere";
   findEnglishNum(text);   }

運行結果:

java統計字符串單詞個數的方法解析

后面還有一些沒有全部截下來

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持服務器之家!

原文鏈接:http://www.cnblogs.com/LFBlog/p/6240906.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 色玖玖综合 | 久色亚洲 | 国产69精品久久久久久久久久 | 在线免费视频a | 久久久久久久久久久av | 99久久免费看精品国产一区 | 久久我不卡 | 9999精品 | 欧美18—19sex性hd按摩 | 黄色片小说| xp123精品视频 | 欧洲精品久久久 | 91网站链接 | 高清做爰免费无遮网站挡 | 美女视频免费一区二区 | 久久久一区二区三区精品 | 国产肥熟 | 深夜毛片免费看 | 国产午夜精品一区二区三区免费 | 欧美一级特黄a | 羞羞的视频免费在线观看 | 在线播放亚洲精品 | 亚洲一区在线不卡 | av在线播放免费观看 | 国产一级小视频 | 午夜亚洲视频 | 羞羞视频入口 | 久久精品视频首页 | 在线亚洲免费视频 | 国产一区免费观看 | 成熟女人特级毛片www免费 | 欧美亚州 | 91九色蝌蚪国产 | 中文字幕www. | 欧美成人理论片乱 | 日日草夜夜操 | 亚洲人成在线播放网站 | 一区二区三区视频在线观看 | 91高清免费 | 欧美精品欧美极品欧美激情 | 在线91视频 |