Here you can find the source of charCountRight(String str, String sub)
public static int charCountRight(String str, String sub)
//package com.java2s; public class Main { public static int charCountRight(String str, String sub) { if (str == null) { return 0; }// ww w . j ava 2 s. co m int charCount = 0; String subStr = str; int currentLength = subStr.length() - sub.length(); while (currentLength >= 0 && subStr.substring(currentLength).equals(sub)) { charCount++; subStr = subStr.substring(0, currentLength); currentLength = subStr.length() - sub.length(); } return charCount; } }