Example usage for java.lang String trim

List of usage examples for java.lang String trim

Introduction

In this page you can find the example usage for java.lang String trim.

Prototype

public String trim() 

Source Link

Document

Returns a string whose value is this string, with all leading and trailing space removed, where space is defined as any character whose codepoint is less than or equal to 'U+0020' (the space character).

Usage

From source file:Main.java

public static boolean isNotEmpty(String s) {
    return s != null && s.length() != 0 && !s.trim().equals("") && !s.trim().equals("null");
}

From source file:Main.java

/**
 * Check if a string is empty (length == 0)
 *
 * @param string , to be checked//from   w  ww.j a  v  a 2 s.  c  o  m
 * @return true if empty
 */
public static boolean isEmpty(String string) {
    if (string == null || string.trim().length() == 0) {
        return true;
    }
    return false;
}

From source file:Main.java

public static boolean isWholeNumber(String string) {
    if (string != null && !string.trim().isEmpty()) {
        return string.matches("\\d*");
    }//from   w ww  . jav  a2 s.c om

    else {
        return false;
    }
}

From source file:Main.java

public static void setText(View view, String val) {
    if (val == null || val.trim().length() < 1)
        return;/*from   w w  w.  jav  a  2s. c  o  m*/
    if (view instanceof TextView) {
        ((TextView) view).setText(val);
    } else if (view instanceof EditText) {
        ((EditText) view).setText(val);
    }
}

From source file:Main.java

public static String fixLastSlash(String str) {
    String res = str == null ? "/" : str.trim() + "/";
    if (res.length() > 2 && res.charAt(res.length() - 2) == '/')
        res = res.substring(0, res.length() - 1);
    return res;//  ww  w . j  a v  a  2s . c  o  m
}

From source file:Main.java

public static String[] getIpAndPort(String ip) {
    if (ip == null || ip.trim().length() < 4) {
        return null;
    }//from   w w  w.  j a  va  2  s  .  c om
    String[] strs = null;

    int index = ip.indexOf(":");
    if (index != -1) {
        strs = ip.split(":");
    } else {
        strs = new String[] { ip, "80" };
    }
    return strs;
}

From source file:Main.java

public static Double getDouble(JTextField txt, Double defaultVal) {
    String str = txt.getText();
    if (str.trim().length() <= 0)
        return defaultVal;

    double val = 0;
    try {/*from   ww  w .j a  v a2 s.  com*/
        val = Double.parseDouble(str);
    } catch (NumberFormatException ex) {
    }
    return new Double(val);
}

From source file:Main.java

public static boolean notEmptyString(Object obj) {
    if (!(obj instanceof String)) {
        return false;
    }//www  .j a  v a  2  s  .  c o m
    String str = (String) obj;
    return str.trim().length() > 0;
}

From source file:Main.java

public static boolean isEmail(String email) {
    if (email == null || email.trim().length() == 0)
        return false;
    String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    Pattern p = Pattern.compile(str);
    Matcher m = p.matcher(email);
    return m.matches();
}

From source file:Main.java

private static void ckeckNullPackageName(String packageName) {
    if (packageName == null || packageName.trim().length() == 0)
        throw new NullPointerException(ERROR_MESSAGE);
}