src/org/kocakosm/pitaya/util/Strings.java
public static int countOccurrences(String str, String sub)
	{
		Parameters.checkNotNull(str);
		int n = 0;
		if (!sub.isEmpty()) {
			int start = 0;
			while (true) {
				start = str.indexOf(sub, start);
				if (start == -1) {
					break;
				}
				start += sub.length();
				n++;
			}
		}
		return n;
	}
public static int countOccurrences(String str, String sub)
	{
		Parameters.checkNotNull(str);
		int n = 0;
		if (!sub.isEmpty()) {
			int start = 0;
			while (true) {
				start = str.indexOf(sub, start);
				if (start == -1) {
					break;
				}
				start += sub.length();
				n++;
			}
		}
		return n;
	}
public static int countOccurrences ( String str , String sub ) { Parameters . checkNotNull ( str ) ; int n = 0 ; if ( ! sub . isEmpty ( ) ) { int start = 0 ; while ( true ) { start = str . indexOf ( sub , start ) ; if ( start == - 1 ) { break ; } start += sub . length ( ) ; n ++ ; } } return n ; }
Counts the occurrences of the substring {@code sub} in {@code str}.

@param str {@code String} to search in.
@param sub {@code String} to search for.

@return the number of occurrences of {@code sub} in {@code str}.

@throws NullPointerException if one of the arguments is {@code null}.
Counts the occurrences of the substring { @code sub } in { @code str } .