public final class ConvertUtils extends Object
| 构造器和说明 |
|---|
ConvertUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
toBoolean(String str)
Converts a String to a boolean (optimised for performance).
|
static boolean |
toBoolean(String val,
boolean defaultValue)
Convert String value to boolean value if parameter value is legal.
|
static Boolean |
toBooleanObject(String str)
Converts a String to a Boolean.
|
static int |
toInt(String val)
Convert String value to int value if parameter value is legal.
|
static int |
toInt(String val,
int defaultValue)
Convert String value to int value if parameter value is legal.
|
static long |
toLong(String val)
Convert String value to long value if parameter value is legal.
|
static long |
toLong(String val,
long defaultValue)
Convert String value to long value if parameter value is legal.
|
public static int toInt(String val)
val - String value which need to be converted to int value.public static int toInt(String val, int defaultValue)
val - valuedefaultValue - default valuepublic static long toLong(String val)
val - String value which need to be converted to int value.public static long toLong(String val, long defaultValue)
val - valuedefaultValue - default valuepublic static boolean toBoolean(String val, boolean defaultValue)
val - valuedefaultValue - default valuepublic static boolean toBoolean(String str)
Converts a String to a boolean (optimised for performance).
'true', 'on', 'y', 't' or 'yes'
(case insensitive) will return true. Otherwise, false is returned.
This method performs 4 times faster (JDK1.4) than
Boolean.valueOf(String). However, this method accepts 'on' and 'yes', 't', 'y' as true values.
BooleanUtils.toBoolean(null) = false
BooleanUtils.toBoolean("true") = true
BooleanUtils.toBoolean("TRUE") = true
BooleanUtils.toBoolean("tRUe") = true
BooleanUtils.toBoolean("on") = true
BooleanUtils.toBoolean("yes") = true
BooleanUtils.toBoolean("false") = false
BooleanUtils.toBoolean("x gti") = false
BooleanUtils.toBooleanObject("y") = true
BooleanUtils.toBooleanObject("n") = false
BooleanUtils.toBooleanObject("t") = true
BooleanUtils.toBooleanObject("f") = false
str - the String to checkfalse if no match or the String is nullpublic static Boolean toBooleanObject(String str)
Converts a String to a Boolean.
'true', 'on', 'y', 't' or 'yes'
(case insensitive) will return true. 'false', 'off', 'n', 'f' or 'no' (case insensitive) will return false. Otherwise, null is returned.
NOTE: This returns null and will throw a NullPointerException if autoboxed to a boolean.
// N.B. case is not significant
BooleanUtils.toBooleanObject(null) = null
BooleanUtils.toBooleanObject("true") = Boolean.TRUE
BooleanUtils.toBooleanObject("T") = Boolean.TRUE // i.e. T[RUE]
BooleanUtils.toBooleanObject("false") = Boolean.FALSE
BooleanUtils.toBooleanObject("f") = Boolean.FALSE // i.e. f[alse]
BooleanUtils.toBooleanObject("No") = Boolean.FALSE
BooleanUtils.toBooleanObject("n") = Boolean.FALSE // i.e. n[o]
BooleanUtils.toBooleanObject("on") = Boolean.TRUE
BooleanUtils.toBooleanObject("ON") = Boolean.TRUE
BooleanUtils.toBooleanObject("off") = Boolean.FALSE
BooleanUtils.toBooleanObject("oFf") = Boolean.FALSE
BooleanUtils.toBooleanObject("yes") = Boolean.TRUE
BooleanUtils.toBooleanObject("Y") = Boolean.TRUE // i.e. Y[ES]
BooleanUtils.toBooleanObject("blue") = null
BooleanUtils.toBooleanObject("true ") = null // trailing space (too long)
BooleanUtils.toBooleanObject("ono") = null // does not match on or no
str - the String to check; upper and lower case are treated as the samenull if no match or null inputCopyright © 2018–2020 Alibaba Group. All rights reserved.