This class tries to handle null input gracefully.
An exception will not be thrown for a null input.
Each method documents its behavior in more detail.
#ThreadSafe#
| Modifier and Type | Field and Description |
|---|---|
| private static final String[] | |
| public static final char | CR
Carriage return character CR ('\r', Unicode 000d). |
| private static final char[] | |
| public static final char | LF
Linefeed character LF ( |
| public static final char | NUL
|
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static int | Returns: the value0 if x == y;
a value less than 0 if x < y; and
a value greater than 0 if x > ythe first x, final char char to comparethe second y)char to compareCompares two |
| public static boolean | Returns: true if less than 128the character to check ch)Tests whether the character is ASCII 7 bit. |
| public static boolean | Returns: true if between 65 and 90 or 97 and 122 inclusivethe character to check ch)Tests whether the character is ASCII 7 bit alphabetic. |
| public static boolean | Returns: true if between 97 and 122 inclusivethe character to check ch)Tests whether the character is ASCII 7 bit alphabetic lower case. |
| public static boolean | Returns: true if between 48 and 57 or 65 and 90 or 97 and 122 inclusivethe character to check ch)Tests whether the character is ASCII 7 bit numeric. |
| public static boolean | Returns: true if between 65 and 90 inclusivethe character to check ch)Tests whether the character is ASCII 7 bit alphabetic upper case. |
| public static boolean | Returns: true if less than 32 or equals 127the character to check ch)Tests whether the character is ASCII 7 bit control. |
| public static boolean | Returns: true if between 48 and 57 inclusivethe character to check ch)Tests whether the character is ASCII 7 bit numeric. |
| public static boolean | Returns: true if between 32 and 126 inclusivethe character to check ch)Tests whether the character is ASCII 7 bit printable. |
| public static boolean | Returns: true if character is a hexadecimal character.the character to test. ch)Tests whether a character is a hexadecimal character. |
| public static boolean | Returns: true if the given char is the character representation of one of the digits from 0 to 7the char to check ch)Tests if the given char is an octal digit. |
| public static char | |
| public static char | |
| public static char | |
| public static char | |
| public static Character | Returns: aCharacter representing c.the character to convert c)
Deprecated
Use
Character#valueOf(char).
Delegates to |
| public static Character | Returns: the Character value of the first letter of the Stringthe character to convert str)Converts the String to a Character using the first character, returning null for empty Strings. |
| public static int | Returns: the int value of the characterthe character to convert ch)Converts the character to the Integer it represents, throwing an exception if the character is not numeric. |
| public static int | Returns: the int value of the characterthe character to convert ch, final int the default value to use if the character is not numeric defaultValue)Converts the character to the Integer it represents, throwing an exception if the character is not numeric. |
| public static int | Returns: the int value of the characterthe character to convert, not null ch)Converts the character to the Integer it represents, throwing an exception if the character is not numeric. |
| public static int | Returns: the int value of the characterthe character to convert ch, final int the default value to use if the character is not numeric defaultValue)Converts the character to the Integer it represents, throwing an exception if the character is not numeric. |
| public static String | Returns: a String containing the one specified characterthe character to convert ch)Converts the character to a String that contains the one character. |
| public static String | |
| public static String | Returns: the escaped Unicode stringthe character to convert ch)Converts the string to the Unicode format ' '. |
| public static String | Returns: the escaped Unicode string, null if null inputthe character to convert, may be null ch)Converts the string to the Unicode format ' '. |
| CHAR_STRING_ARRAY | back to summary |
|---|---|
| private static final String[] CHAR_STRING_ARRAY | |
| CR | back to summary |
|---|---|
| public static final char CR Carriage return character CR ('\r', Unicode 000d).
| |
| HEX_DIGITS | back to summary |
|---|---|
| private static final char[] HEX_DIGITS | |
| LF | back to summary |
|---|---|
| public static final char LF Linefeed character LF (
| |
| NUL | back to summary |
|---|---|
| public static final char NUL
| |
| CharUtils | back to summary |
|---|---|
| public CharUtils()
Deprecated TODO Make private in 4.0.
This constructor is public to permit tools that require a JavaBean instance to operate.
| |
| compare | back to summary |
|---|---|
| public static int compare(final char x, final char y) Compares two
| |
| isAscii | back to summary |
|---|---|
| public static boolean isAscii(final char ch) Tests whether the character is ASCII 7 bit.
CharUtils.isAscii('a') = true
CharUtils.isAscii('A') = true
CharUtils.isAscii('3') = true
CharUtils.isAscii('-') = true
CharUtils.isAscii('\n') = true
CharUtils.isAscii('©') = false
| |
| isAsciiAlpha | back to summary |
|---|---|
| public static boolean isAsciiAlpha(final char ch) Tests whether the character is ASCII 7 bit alphabetic.
CharUtils.isAsciiAlpha('a') = true
CharUtils.isAsciiAlpha('A') = true
CharUtils.isAsciiAlpha('3') = false
CharUtils.isAsciiAlpha('-') = false
CharUtils.isAsciiAlpha('\n') = false
CharUtils.isAsciiAlpha('©') = false
| |
| isAsciiAlphaLower | back to summary |
|---|---|
| public static boolean isAsciiAlphaLower(final char ch) Tests whether the character is ASCII 7 bit alphabetic lower case.
CharUtils.isAsciiAlphaLower('a') = true
CharUtils.isAsciiAlphaLower('A') = false
CharUtils.isAsciiAlphaLower('3') = false
CharUtils.isAsciiAlphaLower('-') = false
CharUtils.isAsciiAlphaLower('\n') = false
CharUtils.isAsciiAlphaLower('©') = false
| |
| isAsciiAlphanumeric | back to summary |
|---|---|
| public static boolean isAsciiAlphanumeric(final char ch) Tests whether the character is ASCII 7 bit numeric.
CharUtils.isAsciiAlphanumeric('a') = true
CharUtils.isAsciiAlphanumeric('A') = true
CharUtils.isAsciiAlphanumeric('3') = true
CharUtils.isAsciiAlphanumeric('-') = false
CharUtils.isAsciiAlphanumeric('\n') = false
CharUtils.isAsciiAlphanumeric('©') = false
| |
| isAsciiAlphaUpper | back to summary |
|---|---|
| public static boolean isAsciiAlphaUpper(final char ch) Tests whether the character is ASCII 7 bit alphabetic upper case.
CharUtils.isAsciiAlphaUpper('a') = false
CharUtils.isAsciiAlphaUpper('A') = true
CharUtils.isAsciiAlphaUpper('3') = false
CharUtils.isAsciiAlphaUpper('-') = false
CharUtils.isAsciiAlphaUpper('\n') = false
CharUtils.isAsciiAlphaUpper('©') = false
| |
| isAsciiControl | back to summary |
|---|---|
| public static boolean isAsciiControl(final char ch) Tests whether the character is ASCII 7 bit control.
CharUtils.isAsciiControl('a') = false
CharUtils.isAsciiControl('A') = false
CharUtils.isAsciiControl('3') = false
CharUtils.isAsciiControl('-') = false
CharUtils.isAsciiControl('\n') = true
CharUtils.isAsciiControl('©') = false
| |
| isAsciiNumeric | back to summary |
|---|---|
| public static boolean isAsciiNumeric(final char ch) Tests whether the character is ASCII 7 bit numeric.
CharUtils.isAsciiNumeric('a') = false
CharUtils.isAsciiNumeric('A') = false
CharUtils.isAsciiNumeric('3') = true
CharUtils.isAsciiNumeric('-') = false
CharUtils.isAsciiNumeric('\n') = false
CharUtils.isAsciiNumeric('©') = false
| |
| isAsciiPrintable | back to summary |
|---|---|
| public static boolean isAsciiPrintable(final char ch) Tests whether the character is ASCII 7 bit printable.
CharUtils.isAsciiPrintable('a') = true
CharUtils.isAsciiPrintable('A') = true
CharUtils.isAsciiPrintable('3') = true
CharUtils.isAsciiPrintable('-') = true
CharUtils.isAsciiPrintable('\n') = false
CharUtils.isAsciiPrintable('©') = false
| |
| isHex | back to summary |
|---|---|
| public static boolean isHex(final char ch) Tests whether a character is a hexadecimal character.
CharUtils.isHex('0') = true
CharUtils.isHex('3') = true
CharUtils.isHex('9') = true
CharUtils.isHex('a') = true
CharUtils.isHex('f') = true
CharUtils.isHex('g') = false
CharUtils.isHex('A') = true
CharUtils.isHex('F') = true
CharUtils.isHex('G') = false
CharUtils.isHex('#') = false
CharUtils.isHex('-') = false
CharUtils.isHex('\n') = false
CharUtils.isHex('©') = false
| |
| isOctal | back to summary |
|---|---|
| public static boolean isOctal(final char ch) Tests if the given char is an octal digit. Octal digits are the character representations of the digits 0 to 7.
| |
| toChar | back to summary |
|---|---|
| public static char toChar(final Character ch) Converts the Character to a char throwing an exception for
CharUtils.toChar(' ') = ' '
CharUtils.toChar('A') = 'A'
CharUtils.toChar(null) throws IllegalArgumentException
| |
| toChar | back to summary |
|---|---|
| public static char toChar(final Character ch, final char defaultValue) Converts the Character to a char handling
CharUtils.toChar(null, 'X') = 'X'
CharUtils.toChar(' ', 'X') = ' '
CharUtils.toChar('A', 'X') = 'A'
| |
| toChar | back to summary |
|---|---|
| public static char toChar(final String str) Converts the String to a char using the first character, throwing an exception on empty Strings.
CharUtils.toChar("A") = 'A'
CharUtils.toChar("BA") = 'B'
CharUtils.toChar(null) throws IllegalArgumentException
CharUtils.toChar("") throws IllegalArgumentException
| |
| toChar | back to summary |
|---|---|
| public static char toChar(final String str, final char defaultValue) Converts the String to a char using the first character, defaulting the value on empty Strings.
CharUtils.toChar(null, 'X') = 'X'
CharUtils.toChar("", 'X') = 'X'
CharUtils.toChar("A", 'X') = 'A'
CharUtils.toChar("BA", 'X') = 'B'
| |
| toCharacterObject | back to summary |
|---|---|
| public static Character toCharacterObject(final char c)
Deprecated Delegates to
| |
| toCharacterObject | back to summary |
|---|---|
| public static Character toCharacterObject(final String str) Converts the String to a Character using the first character, returning null for empty Strings. For ASCII 7 bit characters, this uses a cache that will return the same Character object each time.
CharUtils.toCharacterObject(null) = null
CharUtils.toCharacterObject("") = null
CharUtils.toCharacterObject("A") = 'A'
CharUtils.toCharacterObject("BA") = 'B'
| |
| toIntValue | back to summary |
|---|---|
| public static int toIntValue(final char ch) Converts the character to the Integer it represents, throwing an exception if the character is not numeric. This method converts the char '1' to the int 1 and so on.
CharUtils.toIntValue('3') = 3
CharUtils.toIntValue('A') throws IllegalArgumentException
| |
| toIntValue | back to summary |
|---|---|
| public static int toIntValue(final char ch, final int defaultValue) Converts the character to the Integer it represents, throwing an exception if the character is not numeric. This method converts the char '1' to the int 1 and so on.
CharUtils.toIntValue('3', -1) = 3
CharUtils.toIntValue('A', -1) = -1
| |
| toIntValue | back to summary |
|---|---|
| public static int toIntValue(final Character ch) Converts the character to the Integer it represents, throwing an exception if the character is not numeric. This method converts the char '1' to the int 1 and so on.
CharUtils.toIntValue('3') = 3
CharUtils.toIntValue(null) throws IllegalArgumentException
CharUtils.toIntValue('A') throws IllegalArgumentException
| |
| toIntValue | back to summary |
|---|---|
| public static int toIntValue(final Character ch, final int defaultValue) Converts the character to the Integer it represents, throwing an exception if the character is not numeric. This method converts the char '1' to the int 1 and so on.
CharUtils.toIntValue(null, -1) = -1
CharUtils.toIntValue('3', -1) = 3
CharUtils.toIntValue('A', -1) = -1
| |
| toString | back to summary |
|---|---|
| public static String toString(final char ch) Converts the character to a String that contains the one character. For ASCII 7 bit characters, this uses a cache that will return the same String object each time.
CharUtils.toString(' ') = " "
CharUtils.toString('A') = "A"
| |
| toString | back to summary |
|---|---|
| public static String toString(final Character ch) Converts the character to a String that contains the one character. For ASCII 7 bit characters, this uses a cache that will return the same String object each time. If
CharUtils.toString(null) = null
CharUtils.toString(' ') = " "
CharUtils.toString('A') = "A"
| |
| unicodeEscaped | back to summary |
|---|---|
| public static String unicodeEscaped(final char ch) Converts the string to the Unicode format ' '. This format is the Java source code format.
CharUtils.unicodeEscaped(' ') = " "
CharUtils.unicodeEscaped('A') = "A"
| |
| unicodeEscaped | back to summary |
|---|---|
| public static String unicodeEscaped(final Character ch) Converts the string to the Unicode format ' '. This format is the Java source code format. If
CharUtils.unicodeEscaped(null) = null
CharUtils.unicodeEscaped(' ') = " "
CharUtils.unicodeEscaped('A') = "A"
| |