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

StringsubString(String str, int end)
sub String
return subString(str, 0, end, "...");
Stringsubstring(String str, int index, int length)
substring
if (str == null) {
    return null;
int len = str.length();
if (index + length > len) {
    length = len - index;
return str.substring(index, length);
...
StringsubString(String str, int len)
sub String
if (len < 0) {
    return str;
if ("".equals(str) || str == null) {
    return null;
} else if (str.length() <= len) {
    return str;
} else {
...
Stringsubstring(String str, int len)
substring
len = len * 2;
StringBuffer sb = new StringBuffer();
int counter = 0;
for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);
    if (c < 255) {
        counter++;
    } else {
...
StringsubString(String str, int num, String token)
sub String
String str1 = str;
if (str != null && str.trim().length() > num) {
    str1 = str.substring(0, num);
if (token != null) {
    str1 = str1 + token;
return str1;
...
Stringsubstring(String str, int off, int len)
this method works different from the regular substring method, the regular substring method takes startIndex and endIndex as second and third argument, this method takes offset and length
return str.substring(off, off + len);
StringsubString(String str, int offset, int leng)
sub String
return new String(str.getBytes(), (offset - 1), leng);
Stringsubstring(String str, int start)

Gets a substring from the specified String avoiding exceptions.

A negative start position can be used to start n characters from the end of the String.

A null String will return null.

if (str == null) {
    return null;
if (start < 0) {
    start = str.length() + start; 
if (start < 0) {
    start = 0;
...
Stringsubstring(String str, int start)
substring
if (str == null)
    return null;
if (start < 0)
    start = str.length() + start;
if (start < 0)
    start = 0;
return (start > str.length()) ? "" : str.substring(start);
Stringsubstring(String str, int start)
substring
if (str == null) {
    return null;
if (start < 0) {
    start = str.length() + start; 
if (start < 0) {
    start = 0;
...