code: public static int lastIndexOf(String source, String str) {
          int strLength = str.length();
          // non-surrogate ends
          if (!isTrailSurrogate(str.charAt(0)) && !isLeadSurrogate(str.charAt(strLength - 1))) {
              return source.lastIndexOf(str);
          }
  
          int result = source.lastIndexOf(str);
          if (result >= 0) {
              // check last character
              if (isLeadSurrogate(str.charAt(strLength - 1)) && (result < source.length() - 1)
                      && isTrailSurrogate(source.charAt(result + strLength + 1))) {
                  return lastIndexOf(source, str, result - 1);
              }
              // check first character which is a trail surrogate
              if (isTrailSurrogate(str.charAt(0)) && result > 0
                      && isLeadSurrogate(source.charAt(result - 1))) {
                  return lastIndexOf(source, str, result - 1);
              }
          }
          return result;
      }
docs: Returns the index within the argument UTF16 format Unicode string of the last occurrence of
  the argument string str. This method is implemented based on codepoints, hence a "lead
  surrogate character + trail surrogate character" is treated as one entity.e Hence if the str
  starts with trail surrogate character at index 0, a source with a leading a surrogate
  character before str found at in source will not have a valid match. Vice versa for lead
  surrogates that ends str. See example below.
  <p>
  Examples:<br>
  UTF16.lastIndexOf("abc", "a") returns 0<br>
  UTF16.lastIndexOf("abc\ud800\udc00", "\ud800\udc00") returns 3<br>
  UTF16.lastIndexOf("abc\ud800\udc00", "\ud800") returns -1<br>
  </p>
  <p>
  source is searched backwards starting at the last character.
  </p>
  Note this method is provided as support to jdk 1.3, which does not support supplementary
  characters to its fullest.
  
  @param source UTF16 format Unicode string that will be searched
  @param str UTF16 format Unicode string to search for
  @return the index of the last occurrence of the codepoint in source, or -1 if the codepoint
  does not occur.