Is there any equivalent to String.strip() in android

Solution 1:

You can try upgrading your project to use Java 11, which has the function. Or write it yourself, its trivial.

public static String strip(String value) {
    int firstChar = 0;
    while (firstChar < value.length() && Character.isWhitespace(value.charAt(firstChar))) {
        firstChar++;
    }
    int lastChar = value.length() - 1;
    while (lastChar > firstChar && Character.isWhitespace(value.charAt(lastChar))) {
        lastChar--;
    }
    return value.substring(firstChar, lastChar + 1);
}