http://outofmemory.cn/code-snippet/815/java-zishutongji
一个api,位于apache.commons.lang.StringUtils类下的一个StringUtils.countMatches(paragraph, string);方法,这个方法返回值是一个数字
 
 
代码:

package cn.outofmemory;

import org.apache.commons.lang3.StringUtils;

public class WordCounter {

public static void main(String[] args) {

// String with our paragraph
        String paragraph = "Java Code Geeks (JCGs) is an independent online community focused on creating the"
        + "ultimate Java-to-Java developers resource center; targeted at the technical architect, technical"
        + "team lead (senior developer), project manager and junior developers alike. JCGs serve the Java, "
        + "Scala, Android, SOA, Agile and Telecom communities with daily news written by domain experts, "
        + "articles, tutorials, reviews, announcements, code snippets and open source projects.";

// Declare the word you want to search
        String string = "Java";

// Count word repetitions
        int counter = StringUtils.countMatches(paragraph, string);

// Print the result
        System.out.println("Word <" + string + "> appeared " + counter + " times in the paragraph.");
    }
}


 
 
 

最新文章

  1. mybatis入门基础(八)-----查询缓存
  2. ASP.NET Misconfiguration: Debug Information
  3. C#与Swift异步操作的差异
  4. MySQL ibdata1文件迁移
  5. Sequence.js 实现带有视差滚动特效的图片滑块
  6. uC/OS-II汇编代码
  7. Myeclipse 10 破解说明
  8. ios tweak之binary not signed (use ldid -S)问题解决
  9. ubuntu apt-get
  10. Swift 中的getting和setter的使用
  11. QTP自传之web常用对象
  12. memcached在Windows下的安装
  13. oracle数据库recover和restore的区别
  14. SpringMVC的@ModelAttribute注解简单使用(用户修改信息)
  15. 数列[专杀Splay版]
  16. gradle入门(1-6)将Java项目从maven迁移到gradle
  17. Node.js(day2)
  18. MyBatis-Plus的简单使用
  19. [Android实例] Android Studio插件-自动根据布局生成Activity等代码1.4 (开源)(申明:来源于网络)
  20. epoll的水平触发和边缘触发,以及边缘触发为什么要使用非阻塞IO

热门文章

  1. 基于UDT connect连接通信以及文件传输--客户端
  2. Python-mysql索引
  3. zabbix报警邮件qq邮箱收不到的问题
  4. Matlab与C++混合编程,添加OpenCV库
  5. phpcms编辑器添加一键排版控件
  6. HDU 6336 子矩阵求和
  7. Codeforces Round #325 (Div. 2) Phillip and Trains dp
  8. [COCI2015]ZGODAN
  9. http 头信息详解(转)
  10. socket第三方库 AsyncSocket(GCDAsyncSocket)