tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Jodd > Strings > How to get string occurrence count

How to get string occurrence count 

Jodd is an open-source java library with lot of reusable components and feature rich utilities. This requires the library jodd-3.3.2.jar to be in classpath. The following example shows how to use StringUtil.count() API. It returns the occurrence count of given character or substring in the source string.

File Name  :  
com/bethecoder/tutorials/jodd/utils/StringOccurenceCountTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.jodd.utils;

import jodd.util.StringUtil;

public class StringOccurenceCountTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    System.out.println(StringUtil.count("abbacab"'a'));
    System.out.println(StringUtil.count("abbacab""ab"));
    System.out.println(StringUtil.count("abbacab""bb"));
    System.out.println(StringUtil.count("abbacab""abc"));
  }

}
   

It gives the following output,
3
2
1
0



 
  


  
bl  br