java的boolean與string型別轉換
阿新 • • 發佈:2019-02-04
Boolean.valueOf(“TRUE”)==true//此處的引數true忽略大小寫
其他都是false直接上原始碼:
/** * Returns a {@code Boolean} with a value represented by the * specified string. The {@code Boolean} returned represents a * true value if the string argument is not {@code null} * and is equal, ignoring case, to the string {@code"true"}. * * @param s a string. * @return the {@code Boolean} value represented by the string. */ public static Boolean valueOf(String s) { return toBoolean(s) ? TRUE : FALSE; }
private static boolean toBoolean(String name) { return ((name != null) && name.equalsIgnoreCase("true")); }