Tag Archives: string

Useful isEmpty String method in pure Java

3613906

To ensure empty string:

public static boolean isEmpty(String value) {
    return "".equals(value);
}

Simple and elegant isBlank method in Java

isblank
You may use pure java instead of apache commons in case of defining blank string, like this:

public static boolean isBlank(String value) {
    return value == null || "".equals(value.trim());
}

Convert String to GString in Groovy

groovy-logo-medium
Just use this to convert from string to groovy string:

String someStr = "here must be"
def gstring = "${someStr}"

Check string isBlank method

Meeka_is_blank_by_RGP
To check the string is blank use next:

public static boolean isBlank(String str) {
    int strLen;
    if (str == null || (strLen = str.length()) == 0) {
        return true;
    }
    for (int i = 0; i < strLen; i++) {
        if (!Character.isWhitespace(str.charAt(i))) {
            return false;
        }
    }
    return true;
}

Or just use apache commons for short.

Delete string from array in Java

Useful snipet here:

    String s = "Some super string here...";

    // Get word list
    Pattern patTag = Pattern.compile("<.*?[^<]+>",Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL);
    List aWords = new ArrayList(Arrays.asList(patTag.split(s)));
    
    // Deleting...
    String[] aIgnored = new String[] { "", " ", ",", ", ", ".", ". ", " ", "  " };
    aWords.removeAll(new ArrayList(Arrays.asList(aIgnored)));

As a result, we’ve clear word list.