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

StringsubstringAfter(String str, String separator)

Gets the substring after the first occurrence of a separator.

if (isEmpty(str)) {
    return str;
if (separator == null) {
    return EMPTY;
int pos = str.indexOf(separator);
if (pos == -1) {
...
StringsubstringAfter(String str, String separator)
substring After
if (isEmpty(str)) {
    return str;
} else if (separator == null) {
    return "";
} else {
    int pos = str.indexOf(separator);
    return pos == -1 ? "" : str.substring(pos + separator.length());
StringsubstringAfter(String str, String separator)

Gets the substring after the first occurrence of a separator.

if (isEmpty(str)) {
    return str;
if (separator == null) {
    return EMPTY;
int pos = str.indexOf(separator);
if (pos == -1) {
...
StringsubstringAfter(String string, String delim)
Returns the substring after the delimiter string, not including the delimiter string.
int pos = string.indexOf(delim);
if (pos == 0)
    return string;
else if (pos > 0)
    return string.substring(pos + delim.length());
else
    return null;
StringsubstringAfter(String string, String delimiter)
substring After
int pos = string.indexOf(delimiter);
return pos >= 0 ? string.substring(pos + delimiter.length()) : "";
StringsubstringAfter(String template, String toFind, String defaultTo)
Searches a given string ( template ) for a substring ( toFind ) and returns the portion of the string that follows the substring.
int toFindLength = toFind.length();
int toFindOffset = template.indexOf(toFind);
int substringOffset = toFindOffset + toFindLength;
String returnValue;
if (toFindOffset == -1) { 
    returnValue = defaultTo;
} else {
    returnValue = template.substring(substringOffset);
...
StringsubstringAfter(String text, int index)
substring After
if (index == INDEX_NOT_FOUND) {
    return EMPTY;
return text.substring(index + 1, text.length());
StringsubstringAfter(String text, String after)
Returns the portion of the overall string that comes after the first occurance of the given string.
int indexOf = text.indexOf(after);
if (indexOf == -1) {
    return text;
return text.substring(indexOf + after.length());
StringsubstringAfter(String value, char delim)
substring After
if (value == null) {
    return null;
int pos = value.indexOf(delim);
if (pos >= 0) {
    return value.substring(pos + 1);
return null;
...
StringsubstringAfterFirstIndex(String value)
Omits the first character and returns the remaining string.
if (null == value || value.isEmpty()) {
    return "";
return value.substring(1);