List of usage examples for java.lang String isEmpty
public boolean isEmpty()
From source file:Main.java
/** * Will parse a color and set it as text color * @param color a string that can be converted into a hex color e.g #000fff * @param v textview//from w ww .j a v a 2 s .c o m */ public static void setTextColor(String color, TextView v) { v.setTextColor(Color.parseColor(color.isEmpty() ? "#000000" : color)); }
From source file:Main.java
private static String unescape(String str) { StringBuilder sb = new StringBuilder(); String[] codeStrs = str.split("\\\\u"); for (String codeStr : codeStrs) { if (codeStr.isEmpty()) { continue; }// w w w . jav a2 s . c o m try { if (codeStr.length() <= 4) { sb.append(Character.valueOf((char) Integer.parseInt(codeStr, 16))); } else { sb.append(Character.valueOf((char) Integer.parseInt(codeStr.substring(0, 4), 16))); sb.append(codeStr.substring(4)); } } catch (NumberFormatException e) { sb.append(codeStr); } } return sb.toString(); }
From source file:Main.java
/** * remove more than two spaces or newlines *///from w ww . j ava2s.c o m public static String innerTrim(String str) { if (str.isEmpty()) return ""; StringBuilder sb = new StringBuilder(); boolean previousSpace = false; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == ' ' || (int) c == 9) { previousSpace = true; continue; } if (previousSpace) sb.append(' '); previousSpace = false; sb.append(c); } return sb.toString().trim(); }
From source file:Main.java
/** * remove more than two spaces or newlines *//* w w w . j a va 2s . c o m*/ public static String innerTrim(String str) { if (str.isEmpty()) return ""; StringBuilder sb = new StringBuilder(str.length()); boolean previousSpace = false; for (int i = 0, length = str.length(); i < length; i++) { char c = str.charAt(i); if (c == ' ' || (int) c == 9 || c == '\n') { previousSpace = true; continue; } if (previousSpace) sb.append(' '); previousSpace = false; sb.append(c); } return sb.toString().trim(); }
From source file:Main.java
/** * remove more than two spaces or newlines *//*from ww w. j a v a2s . com*/ public static String innerTrim(String str) { if (str.isEmpty()) return ""; StringBuilder sb = new StringBuilder(); boolean previousSpace = false; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == ' ' || (int) c == 9 || c == '\n') { previousSpace = true; continue; } if (previousSpace) sb.append(' '); previousSpace = false; sb.append(c); } return sb.toString().trim(); }
From source file:example.ToCommonsEmpty.java
public static void main2(String[] args) { String s = ""; boolean a = s == null || s.length() == 0; boolean b = s == null || s.isEmpty(); boolean c = s != null && s.isEmpty(); boolean d = s != null && s.length() == 0; }
From source file:Main.java
public static Boolean IsInt(String string) { try {/*www. j a v a 2 s .c om*/ if (string == null || string.isEmpty()) { return false; } else { return Integer.parseInt(string) > 0; } } catch (Exception e) { return false; } }
From source file:Main.java
public static long strToLong(String strVal) { if (strVal == null || strVal.isEmpty()) return 0; byte[] vals = strVal.getBytes(); int tailFlag = vals.length > 8 ? 8 : vals.length; long result = 0; for (int i = 0; i < tailFlag; i++) { result = result << 8;/*ww w .j a va2 s . co m*/ result += vals[i]; } return result; }
From source file:Main.java
public static Boolean IsNullOrEmpty(String string) { try {/*from ww w . ja v a 2s . co m*/ if (string == null || string.isEmpty()) { return true; } else { return false; } } catch (Exception e) { return true; } }
From source file:Main.java
public static int parseColorFromString(String color) { int colorInt; if (color != null && !color.isEmpty() && !color.substring(0, 1).equals("#")) { colorInt = Color.parseColor("#" + color); } else {//from w w w .java2s. co m colorInt = Color.parseColor(color); } return colorInt; }