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

StringsubStr(String str, int len)
sub Str
if (isEmpty(str)) {
    return "";
if (str.length() >= len) {
    return str.substring(0, len) + "..";
} else {
    return str;
Stringsubstr(String str, int length)
safe substring, without exception
if (str == null) {
    return str;
if (length < str.length()) {
    return str.substring(0, length);
return str;
StringsubStr(String str, int limit)
sub Str
String result = str.substring(0, 17);
int subLen = 17;
for (int i = 0; i < limit; i++) {
    if (limit < getEncodingByteLen(
            str.substring(0, (subLen + i) > str.length() ? str.length() : (subLen)))) {
        result = str.substring(0, subLen + i - 1);
        break;
    if ((subLen + i) > str.length()) {
        result = str.substring(0, str.length() - 1);
        break;
return result;
StringsubStr(String str, int maxLen)
sub Str
if (str == null) {
    return null;
if (maxLen < 1) {
    return str;
if (str.length() > maxLen) {
    return str.substring(0, maxLen) + "...";
...
Stringsubstr(String str, int startIndex, int length)
substr
return substring(str, startIndex, startIndex + length);
Stringsubstr(String substr1, String substr2)
substr
String substr = "";
int size = Math.min(substr1.length(), substr2.length());
for (int i = 0; i < size; i++) {
    if (substr1.charAt(i) == substr2.charAt(i))
        substr += substr1.charAt(i);
    else
        break;
return substr;
Stringsubstr(String what, int begin, int end)
substr
if (begin > end) {
    return "";
return what.substring(Math.max(0, begin), Math.min(end, what.length() - 1));
Objectsubstr(StringBuffer buf)
substr
return (buf == null || buf.length() <= 1 ? "" : buf.substring(0, buf.length() - 1));
double[]substract(double[] a, double[] b)
Subtract the second array from the first one and returns the result.
double[] out = new double[a.length];
for (int i = 0; i < a.length; i++) {
    out[i] = a[i] - b[i];
return out;
double[]substract(double[] a, double[] b)
substract
if (a.length != b.length) {
    throw new IllegalArgumentException("Arrays must be equal length");
double[] c = new double[a.length];
for (int i = 0; i < a.length; i++) {
    c[i] = a[i] - b[i];
return c;
...