zoukankan      html  css  js  c++  java
  • java 实现统计某段文字在内容中出现的次数

    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.");
        }
    }

     
     
     
  • 相关阅读:
    微信多业务
    jps命令
    三白话经典算法系列 Shell排序实现
    无法识别的属性“targetFramework”。请注意,属性名是大写和小写。错误的解决方案
    Timus 1777. Anindilyakwa 奇怪的问题计数
    tokumx经营报表
    Quartz CronTrigger应用
    HDU 3681 BFS&像缩进DP&二分法
    01背包问题
    Web模板
  • 原文地址:https://www.cnblogs.com/svennee/p/4082827.html
Copyright © 2011-2022 走看看