Java Utililty Methods String Sub String

List of utility methods to do String Sub String

Description

The list of methods to do String Sub String are organized into topic(s).

Method

StringsubStrings(String str1, String str2)
sub Strings
int string2Length = str2.length();
int s = str1.indexOf(str2);
return str1.substring(0, s) + str1.substring(s + string2Length);
String[]substrings(String[] arr, int start, int end)
Return specified substrings for all the members of the given array.
String[] subs = new String[arr.length];
for (int i = 0; i < arr.length; ++i) {
    subs[i] = safeSubstr(arr[i], start, end);
return subs;
IntegersubStringToInteger(String src, String start, String to)
Example: subString("12345","1","4")=23
return stringToInteger(subString(src, start, to));
StringsubstringToLast(final String str, final String separator)
substring To Last
if (isEmpty(str) || isEmpty(separator)) {
    return str;
int pos = str.lastIndexOf(separator);
if (pos == -1) {
    return str;
return str.substring(pos + 1, str.length());
...
StringsubstringUntil(String org, int begin, char term)
substring Until
int i = org.indexOf(term, begin);
if (i == -1)
    return org.substring(begin);
return org.substring(begin, i);
StringsubstringUntilMatch(String string, String match)
substring Until Match
int index = string.indexOf(match);
return (index == -1) ? string : string.substring(0, index);
StringsubStringWhiteSpaces(String str, int maxLen)
Retorna uma sub string de tamanho maximo maxlen, dividindo a string original por espacos
if (str == null)
    return null;
if (maxLen < 1)
    return "";
int size = str.length();
if (maxLen >= size)
    return str;
String ini = str.substring(0, maxLen);
...
StringsubStringWith3Point(String inputStr, int beginIndex, int length)
sub String With Point
int strLength = inputStr.length();
if (beginIndex >= strLength) {
    return "";
if (beginIndex + length >= strLength) {
    return inputStr.substring(beginIndex);
return inputStr.substring(beginIndex, beginIndex + length - 1) + "...";
...
intsubStrOccurences(String str, String findStr)
sub Str Occurences
int lastIndex = 0, count = 0;
while (lastIndex != -1) {
    lastIndex = str.indexOf(findStr, lastIndex);
    if (lastIndex != -1) {
        count++;
        lastIndex += findStr.length();
return count;
StringsubStrTime(String strTime)
sub Str Time
String inTime = strTime.substring(0, 2);
String outTime = strTime.substring(2, strTime.length());
return inTime + ":" + outTime;