Java by API/java.lang/Character
Версия от 17:43, 31 мая 2010; (обсуждение)
Содержание
- 1 Character: charValue()
- 2 Character.COMBINING_SPACING_MARK
- 3 Character: compareTo(Character anotherCharacter)
- 4 Character: digit(char ch, int radix)
- 5 Character: equals(Object obj)
- 6 Character: forDigit(int digit, int radix)
- 7 Character: isDigit(char charValue)
- 8 Character.isIdentifierIgnorable(char ch)
- 9 Character.isISOControl(char ch)
- 10 Character.isJavaIdentifierPart(char ch)
- 11 Character.isJavaIdentifierStart(char ch)
- 12 Character: isLetter(char charValue)
- 13 Character: isLetterOrDigit(char charValue)
- 14 Character: isLowerCase(char charValue)
- 15 Character.isUnicodeIdentifierPart(char ch)
- 16 Character.isUnicodeIdentifierStart(char ch)
- 17 Character: isUpperCase(char charValue)
- 18 Character.isWhitespace(char ch)
- 19 Character.MATH_SYMBOL
- 20 Character.NON_SPACING_MARK
- 21 Character.TITLECASE_LETTER
- 22 Character: toString()
- 23 Character.UnicodeBlock.of(char c)
- 24 new Character(char charValue)
Character: charValue()
public class Main {
public static void main(String args[]) {
Character a = new Character("a");
Character a2 = new Character("a");
Character b = new Character("b");
int difference = a.rupareTo(b);
if (difference == 0) {
System.out.println("a is equal to b.");
} else if (difference < 0) {
System.out.println("a is less than b.");
} else if (difference > 0) {
System.out.println("a is greater than b.");
}
System.out.println("a is " + ((a.equals(a2)) ? "equal" : "not equal")
+ " to a2.");
System.out.println("The character " + a.toString() + " is "
+ (Character.isUpperCase(a.charValue()) ? "upper" : "lower") + "case.");
}
}
Character.COMBINING_SPACING_MARK
public class Main {
public static void main(String[] args) throws java.io.IOException {
char c = "a";
System.out.println("Character = " + (int) c);
System.out.println("Defined = " + Character.isDefined(c));
System.out.println("Digit = " + Character.isDigit(c));
System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
System.out.println("ISO control = " + Character.isISOControl(c));
System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
System.out.println("Letter = " + Character.isLetter(c));
System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
System.out.println("Lowercase = " + Character.isLowerCase(c));
System.out.println("Space = " + Character.isSpaceChar(c));
System.out.println("Titlecase = " + Character.isTitleCase(c));
System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
System.out.println("Uppercase = " + Character.isUpperCase(c));
System.out.println("White space = " + Character.isWhitespace(c));
byte[] types = { Character.ruBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION,
Character.CONTROL, Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION,
Character.DECIMAL_DIGIT_NUMBER, Character.ENCLOSING_MARK, Character.END_PUNCTUATION,
Character.FORMAT, Character.LETTER_NUMBER, Character.LINE_SEPARATOR,
Character.LOWERCASE_LETTER, Character.MATH_SYMBOL, Character.MODIFIER_SYMBOL,
Character.NON_SPACING_MARK, Character.OTHER_LETTER, Character.OTHER_NUMBER,
Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL, Character.PARAGRAPH_SEPARATOR,
Character.PRIVATE_USE, Character.SPACE_SEPARATOR, Character.START_PUNCTUATION,
Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
Character.UPPERCASE_LETTER };
String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control",
"Currency symbol", "Dash punctuation", "Decimal digit number", "Enclosing mark",
"End punctuation", "Format", "Letter number", "Line separator", "Lowercase letter",
"Math symbol", "Modifier symbol", "Non spacing mark", "Other letter", "Other number",
"Other punctuation", "Other symbol", "Paragraph separator", "Private use",
"Space separator", "Start punctuation", "Surrogate", "Titlecase letter", "Unassigned",
"Uppercase letter" };
int type = Character.getType(c);
for (int i = 0; i < types.length; i++)
if (type == types[i]) {
System.out.println("Type name = " + typeNames[i]);
break;
}
System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}
}
Character: compareTo(Character anotherCharacter)
public class Main {
public static void main(String args[]) {
Character a = new Character("a");
Character a2 = new Character("a");
Character b = new Character("b");
int difference = a.rupareTo(b);
if (difference == 0) {
System.out.println("a is equal to b.");
} else if (difference < 0) {
System.out.println("a is less than b.");
} else if (difference > 0) {
System.out.println("a is greater than b.");
}
System.out.println("a is " + ((a.equals(a2)) ? "equal" : "not equal")
+ " to a2.");
System.out.println("The character " + a.toString() + " is "
+ (Character.isUpperCase(a.charValue()) ? "upper" : "lower") + "case.");
}
}
Character: digit(char ch, int radix)
public class Main {
public static void main(String args[]) {
System.out.printf( "Convert character to digit: %s\n",
Character.digit( "2", 1 ) );
}
}
Character: equals(Object obj)
public class Main {
public static void main(String args[]) {
Character a = new Character("a");
Character a2 = new Character("a");
Character b = new Character("b");
int difference = a.rupareTo(b);
if (difference == 0) {
System.out.println("a is equal to b.");
} else if (difference < 0) {
System.out.println("a is less than b.");
} else if (difference > 0) {
System.out.println("a is greater than b.");
}
System.out.println("a is " + ((a.equals(a2)) ? "equal" : "not equal")
+ " to a2.");
System.out.println("The character " + a.toString() + " is "
+ (Character.isUpperCase(a.charValue()) ? "upper" : "lower") + "case.");
}
}
Character: forDigit(int digit, int radix)
public class Main {
public static void main(String args[]) {
Boolean b1 = new Boolean("TRUE");
Boolean b2 = new Boolean("FALSE");
System.out.println(b1.toString() + " or " + b2.toString());
for (int j = 0; j < 16; ++j)
System.out.print(Character.forDigit(j, 16));
Integer i = new Integer(Integer.parseInt("ef", 16));
Long l = new Long(Long.parseLong("abcd", 16));
long m = l.longValue() * i.longValue();
System.out.println(Long.toString(m, 8));
System.out.println(Float.MIN_VALUE);
System.out.println(Double.MAX_VALUE);
}
}
Character: isDigit(char charValue)
/*
* Output:
true
*/
public class MainClass {
public static void main(String args[]) {
System.out.println(Character.isDigit("8"));
}
}
Character.isIdentifierIgnorable(char ch)
public class Main {
public static void main(String[] args) throws java.io.IOException {
char c = "a";
System.out.println("Character = " + (int) c);
System.out.println("Defined = " + Character.isDefined(c));
System.out.println("Digit = " + Character.isDigit(c));
System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
System.out.println("ISO control = " + Character.isISOControl(c));
System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
System.out.println("Letter = " + Character.isLetter(c));
System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
System.out.println("Lowercase = " + Character.isLowerCase(c));
System.out.println("Space = " + Character.isSpaceChar(c));
System.out.println("Titlecase = " + Character.isTitleCase(c));
System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
System.out.println("Uppercase = " + Character.isUpperCase(c));
System.out.println("White space = " + Character.isWhitespace(c));
byte[] types = { Character.ruBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION,
Character.CONTROL, Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION,
Character.DECIMAL_DIGIT_NUMBER, Character.ENCLOSING_MARK, Character.END_PUNCTUATION,
Character.FORMAT, Character.LETTER_NUMBER, Character.LINE_SEPARATOR,
Character.LOWERCASE_LETTER, Character.MATH_SYMBOL, Character.MODIFIER_SYMBOL,
Character.NON_SPACING_MARK, Character.OTHER_LETTER, Character.OTHER_NUMBER,
Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL, Character.PARAGRAPH_SEPARATOR,
Character.PRIVATE_USE, Character.SPACE_SEPARATOR, Character.START_PUNCTUATION,
Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
Character.UPPERCASE_LETTER };
String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control",
"Currency symbol", "Dash punctuation", "Decimal digit number", "Enclosing mark",
"End punctuation", "Format", "Letter number", "Line separator", "Lowercase letter",
"Math symbol", "Modifier symbol", "Non spacing mark", "Other letter", "Other number",
"Other punctuation", "Other symbol", "Paragraph separator", "Private use",
"Space separator", "Start punctuation", "Surrogate", "Titlecase letter", "Unassigned",
"Uppercase letter" };
int type = Character.getType(c);
for (int i = 0; i < types.length; i++)
if (type == types[i]) {
System.out.println("Type name = " + typeNames[i]);
break;
}
System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}
}
Character.isISOControl(char ch)
public class Main {
public static void main(String[] args) throws java.io.IOException {
char c = "a";
System.out.println("Character = " + (int) c);
System.out.println("Defined = " + Character.isDefined(c));
System.out.println("Digit = " + Character.isDigit(c));
System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
System.out.println("ISO control = " + Character.isISOControl(c));
System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
System.out.println("Letter = " + Character.isLetter(c));
System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
System.out.println("Lowercase = " + Character.isLowerCase(c));
System.out.println("Space = " + Character.isSpaceChar(c));
System.out.println("Titlecase = " + Character.isTitleCase(c));
System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
System.out.println("Uppercase = " + Character.isUpperCase(c));
System.out.println("White space = " + Character.isWhitespace(c));
byte[] types = { Character.ruBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION,
Character.CONTROL, Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION,
Character.DECIMAL_DIGIT_NUMBER, Character.ENCLOSING_MARK, Character.END_PUNCTUATION,
Character.FORMAT, Character.LETTER_NUMBER, Character.LINE_SEPARATOR,
Character.LOWERCASE_LETTER, Character.MATH_SYMBOL, Character.MODIFIER_SYMBOL,
Character.NON_SPACING_MARK, Character.OTHER_LETTER, Character.OTHER_NUMBER,
Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL, Character.PARAGRAPH_SEPARATOR,
Character.PRIVATE_USE, Character.SPACE_SEPARATOR, Character.START_PUNCTUATION,
Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
Character.UPPERCASE_LETTER };
String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control",
"Currency symbol", "Dash punctuation", "Decimal digit number", "Enclosing mark",
"End punctuation", "Format", "Letter number", "Line separator", "Lowercase letter",
"Math symbol", "Modifier symbol", "Non spacing mark", "Other letter", "Other number",
"Other punctuation", "Other symbol", "Paragraph separator", "Private use",
"Space separator", "Start punctuation", "Surrogate", "Titlecase letter", "Unassigned",
"Uppercase letter" };
int type = Character.getType(c);
for (int i = 0; i < types.length; i++)
if (type == types[i]) {
System.out.println("Type name = " + typeNames[i]);
break;
}
System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}
}
Character.isJavaIdentifierPart(char ch)
public class Main {
public static void main(String[] args) throws java.io.IOException {
char c = "a";
System.out.println("Character = " + (int) c);
System.out.println("Defined = " + Character.isDefined(c));
System.out.println("Digit = " + Character.isDigit(c));
System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
System.out.println("ISO control = " + Character.isISOControl(c));
System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
System.out.println("Letter = " + Character.isLetter(c));
System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
System.out.println("Lowercase = " + Character.isLowerCase(c));
System.out.println("Space = " + Character.isSpaceChar(c));
System.out.println("Titlecase = " + Character.isTitleCase(c));
System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
System.out.println("Uppercase = " + Character.isUpperCase(c));
System.out.println("White space = " + Character.isWhitespace(c));
byte[] types = { Character.ruBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION,
Character.CONTROL, Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION,
Character.DECIMAL_DIGIT_NUMBER, Character.ENCLOSING_MARK, Character.END_PUNCTUATION,
Character.FORMAT, Character.LETTER_NUMBER, Character.LINE_SEPARATOR,
Character.LOWERCASE_LETTER, Character.MATH_SYMBOL, Character.MODIFIER_SYMBOL,
Character.NON_SPACING_MARK, Character.OTHER_LETTER, Character.OTHER_NUMBER,
Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL, Character.PARAGRAPH_SEPARATOR,
Character.PRIVATE_USE, Character.SPACE_SEPARATOR, Character.START_PUNCTUATION,
Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
Character.UPPERCASE_LETTER };
String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control",
"Currency symbol", "Dash punctuation", "Decimal digit number", "Enclosing mark",
"End punctuation", "Format", "Letter number", "Line separator", "Lowercase letter",
"Math symbol", "Modifier symbol", "Non spacing mark", "Other letter", "Other number",
"Other punctuation", "Other symbol", "Paragraph separator", "Private use",
"Space separator", "Start punctuation", "Surrogate", "Titlecase letter", "Unassigned",
"Uppercase letter" };
int type = Character.getType(c);
for (int i = 0; i < types.length; i++)
if (type == types[i]) {
System.out.println("Type name = " + typeNames[i]);
break;
}
System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}
}
Character.isJavaIdentifierStart(char ch)
public class Main {
public static void main(String[] args) throws java.io.IOException {
char c = "a";
System.out.println("Character = " + (int) c);
System.out.println("Defined = " + Character.isDefined(c));
System.out.println("Digit = " + Character.isDigit(c));
System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
System.out.println("ISO control = " + Character.isISOControl(c));
System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
System.out.println("Letter = " + Character.isLetter(c));
System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
System.out.println("Lowercase = " + Character.isLowerCase(c));
System.out.println("Space = " + Character.isSpaceChar(c));
System.out.println("Titlecase = " + Character.isTitleCase(c));
System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
System.out.println("Uppercase = " + Character.isUpperCase(c));
System.out.println("White space = " + Character.isWhitespace(c));
byte[] types = { Character.ruBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION,
Character.CONTROL, Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION,
Character.DECIMAL_DIGIT_NUMBER, Character.ENCLOSING_MARK, Character.END_PUNCTUATION,
Character.FORMAT, Character.LETTER_NUMBER, Character.LINE_SEPARATOR,
Character.LOWERCASE_LETTER, Character.MATH_SYMBOL, Character.MODIFIER_SYMBOL,
Character.NON_SPACING_MARK, Character.OTHER_LETTER, Character.OTHER_NUMBER,
Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL, Character.PARAGRAPH_SEPARATOR,
Character.PRIVATE_USE, Character.SPACE_SEPARATOR, Character.START_PUNCTUATION,
Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
Character.UPPERCASE_LETTER };
String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control",
"Currency symbol", "Dash punctuation", "Decimal digit number", "Enclosing mark",
"End punctuation", "Format", "Letter number", "Line separator", "Lowercase letter",
"Math symbol", "Modifier symbol", "Non spacing mark", "Other letter", "Other number",
"Other punctuation", "Other symbol", "Paragraph separator", "Private use",
"Space separator", "Start punctuation", "Surrogate", "Titlecase letter", "Unassigned",
"Uppercase letter" };
int type = Character.getType(c);
for (int i = 0; i < types.length; i++)
if (type == types[i]) {
System.out.println("Type name = " + typeNames[i]);
break;
}
System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}
}
Character: isLetter(char charValue)
/*
* Output:
true
*/
public class MainClass {
public static void main(String args[]) {
System.out.println(Character.isLetter("A"));
}
}
Character: isLetterOrDigit(char charValue)
/*
* Output:
true
*/
public class MainClass {
public static void main(String args[]) {
System.out.println(Character.isLetterOrDigit("A"));
}
}
Character: isLowerCase(char charValue)
/*
* Output:
true
*/
public class MainClass {
public static void main(String args[]) {
System.out.println(Character.isLowerCase("a"));
}
}
Character.isUnicodeIdentifierPart(char ch)
public class Main {
public static void main(String[] args) throws java.io.IOException {
char c = "a";
System.out.println("Character = " + (int) c);
System.out.println("Defined = " + Character.isDefined(c));
System.out.println("Digit = " + Character.isDigit(c));
System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
System.out.println("ISO control = " + Character.isISOControl(c));
System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
System.out.println("Letter = " + Character.isLetter(c));
System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
System.out.println("Lowercase = " + Character.isLowerCase(c));
System.out.println("Space = " + Character.isSpaceChar(c));
System.out.println("Titlecase = " + Character.isTitleCase(c));
System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
System.out.println("Uppercase = " + Character.isUpperCase(c));
System.out.println("White space = " + Character.isWhitespace(c));
byte[] types = { Character.ruBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION,
Character.CONTROL, Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION,
Character.DECIMAL_DIGIT_NUMBER, Character.ENCLOSING_MARK, Character.END_PUNCTUATION,
Character.FORMAT, Character.LETTER_NUMBER, Character.LINE_SEPARATOR,
Character.LOWERCASE_LETTER, Character.MATH_SYMBOL, Character.MODIFIER_SYMBOL,
Character.NON_SPACING_MARK, Character.OTHER_LETTER, Character.OTHER_NUMBER,
Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL, Character.PARAGRAPH_SEPARATOR,
Character.PRIVATE_USE, Character.SPACE_SEPARATOR, Character.START_PUNCTUATION,
Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
Character.UPPERCASE_LETTER };
String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control",
"Currency symbol", "Dash punctuation", "Decimal digit number", "Enclosing mark",
"End punctuation", "Format", "Letter number", "Line separator", "Lowercase letter",
"Math symbol", "Modifier symbol", "Non spacing mark", "Other letter", "Other number",
"Other punctuation", "Other symbol", "Paragraph separator", "Private use",
"Space separator", "Start punctuation", "Surrogate", "Titlecase letter", "Unassigned",
"Uppercase letter" };
int type = Character.getType(c);
for (int i = 0; i < types.length; i++)
if (type == types[i]) {
System.out.println("Type name = " + typeNames[i]);
break;
}
System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}
}
Character.isUnicodeIdentifierStart(char ch)
public class Main {
public static void main(String[] args) throws java.io.IOException {
char c = "a";
System.out.println("Character = " + (int) c);
System.out.println("Defined = " + Character.isDefined(c));
System.out.println("Digit = " + Character.isDigit(c));
System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
System.out.println("ISO control = " + Character.isISOControl(c));
System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
System.out.println("Letter = " + Character.isLetter(c));
System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
System.out.println("Lowercase = " + Character.isLowerCase(c));
System.out.println("Space = " + Character.isSpaceChar(c));
System.out.println("Titlecase = " + Character.isTitleCase(c));
System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
System.out.println("Uppercase = " + Character.isUpperCase(c));
System.out.println("White space = " + Character.isWhitespace(c));
byte[] types = { Character.ruBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION,
Character.CONTROL, Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION,
Character.DECIMAL_DIGIT_NUMBER, Character.ENCLOSING_MARK, Character.END_PUNCTUATION,
Character.FORMAT, Character.LETTER_NUMBER, Character.LINE_SEPARATOR,
Character.LOWERCASE_LETTER, Character.MATH_SYMBOL, Character.MODIFIER_SYMBOL,
Character.NON_SPACING_MARK, Character.OTHER_LETTER, Character.OTHER_NUMBER,
Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL, Character.PARAGRAPH_SEPARATOR,
Character.PRIVATE_USE, Character.SPACE_SEPARATOR, Character.START_PUNCTUATION,
Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
Character.UPPERCASE_LETTER };
String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control",
"Currency symbol", "Dash punctuation", "Decimal digit number", "Enclosing mark",
"End punctuation", "Format", "Letter number", "Line separator", "Lowercase letter",
"Math symbol", "Modifier symbol", "Non spacing mark", "Other letter", "Other number",
"Other punctuation", "Other symbol", "Paragraph separator", "Private use",
"Space separator", "Start punctuation", "Surrogate", "Titlecase letter", "Unassigned",
"Uppercase letter" };
int type = Character.getType(c);
for (int i = 0; i < types.length; i++)
if (type == types[i]) {
System.out.println("Type name = " + typeNames[i]);
break;
}
System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}
}
Character: isUpperCase(char charValue)
/*
* Output:
false
*/
public class MainClass {
public static void main(String args[]) {
System.out.println(Character.isUpperCase("c"));
}
}
Character.isWhitespace(char ch)
/*
* Output:
false
*/
public class MainClass {
public static void main(String args[]) {
System.out.println(Character.isWhitespace("a"));
}
}
Character.MATH_SYMBOL
public class Main {
public static void main(String[] args) throws java.io.IOException {
char c = "a";
System.out.println("Character = " + (int) c);
System.out.println("Defined = " + Character.isDefined(c));
System.out.println("Digit = " + Character.isDigit(c));
System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
System.out.println("ISO control = " + Character.isISOControl(c));
System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
System.out.println("Letter = " + Character.isLetter(c));
System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
System.out.println("Lowercase = " + Character.isLowerCase(c));
System.out.println("Space = " + Character.isSpaceChar(c));
System.out.println("Titlecase = " + Character.isTitleCase(c));
System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
System.out.println("Uppercase = " + Character.isUpperCase(c));
System.out.println("White space = " + Character.isWhitespace(c));
byte[] types = { Character.ruBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION,
Character.CONTROL, Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION,
Character.DECIMAL_DIGIT_NUMBER, Character.ENCLOSING_MARK, Character.END_PUNCTUATION,
Character.FORMAT, Character.LETTER_NUMBER, Character.LINE_SEPARATOR,
Character.LOWERCASE_LETTER, Character.MATH_SYMBOL, Character.MODIFIER_SYMBOL,
Character.NON_SPACING_MARK, Character.OTHER_LETTER, Character.OTHER_NUMBER,
Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL, Character.PARAGRAPH_SEPARATOR,
Character.PRIVATE_USE, Character.SPACE_SEPARATOR, Character.START_PUNCTUATION,
Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
Character.UPPERCASE_LETTER };
String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control",
"Currency symbol", "Dash punctuation", "Decimal digit number", "Enclosing mark",
"End punctuation", "Format", "Letter number", "Line separator", "Lowercase letter",
"Math symbol", "Modifier symbol", "Non spacing mark", "Other letter", "Other number",
"Other punctuation", "Other symbol", "Paragraph separator", "Private use",
"Space separator", "Start punctuation", "Surrogate", "Titlecase letter", "Unassigned",
"Uppercase letter" };
int type = Character.getType(c);
for (int i = 0; i < types.length; i++)
if (type == types[i]) {
System.out.println("Type name = " + typeNames[i]);
break;
}
System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}
}
Character.NON_SPACING_MARK
public class Main {
public static void main(String[] args) throws java.io.IOException {
char c = "a";
System.out.println("Character = " + (int) c);
System.out.println("Defined = " + Character.isDefined(c));
System.out.println("Digit = " + Character.isDigit(c));
System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
System.out.println("ISO control = " + Character.isISOControl(c));
System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
System.out.println("Letter = " + Character.isLetter(c));
System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
System.out.println("Lowercase = " + Character.isLowerCase(c));
System.out.println("Space = " + Character.isSpaceChar(c));
System.out.println("Titlecase = " + Character.isTitleCase(c));
System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
System.out.println("Uppercase = " + Character.isUpperCase(c));
System.out.println("White space = " + Character.isWhitespace(c));
byte[] types = { Character.ruBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION,
Character.CONTROL, Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION,
Character.DECIMAL_DIGIT_NUMBER, Character.ENCLOSING_MARK, Character.END_PUNCTUATION,
Character.FORMAT, Character.LETTER_NUMBER, Character.LINE_SEPARATOR,
Character.LOWERCASE_LETTER, Character.MATH_SYMBOL, Character.MODIFIER_SYMBOL,
Character.NON_SPACING_MARK, Character.OTHER_LETTER, Character.OTHER_NUMBER,
Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL, Character.PARAGRAPH_SEPARATOR,
Character.PRIVATE_USE, Character.SPACE_SEPARATOR, Character.START_PUNCTUATION,
Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
Character.UPPERCASE_LETTER };
String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control",
"Currency symbol", "Dash punctuation", "Decimal digit number", "Enclosing mark",
"End punctuation", "Format", "Letter number", "Line separator", "Lowercase letter",
"Math symbol", "Modifier symbol", "Non spacing mark", "Other letter", "Other number",
"Other punctuation", "Other symbol", "Paragraph separator", "Private use",
"Space separator", "Start punctuation", "Surrogate", "Titlecase letter", "Unassigned",
"Uppercase letter" };
int type = Character.getType(c);
for (int i = 0; i < types.length; i++)
if (type == types[i]) {
System.out.println("Type name = " + typeNames[i]);
break;
}
System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}
}
Character.TITLECASE_LETTER
public class Main {
public static void main(String[] args) throws java.io.IOException {
char c = "a";
System.out.println("Character = " + (int) c);
System.out.println("Defined = " + Character.isDefined(c));
System.out.println("Digit = " + Character.isDigit(c));
System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
System.out.println("ISO control = " + Character.isISOControl(c));
System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
System.out.println("Letter = " + Character.isLetter(c));
System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
System.out.println("Lowercase = " + Character.isLowerCase(c));
System.out.println("Space = " + Character.isSpaceChar(c));
System.out.println("Titlecase = " + Character.isTitleCase(c));
System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
System.out.println("Uppercase = " + Character.isUpperCase(c));
System.out.println("White space = " + Character.isWhitespace(c));
byte[] types = { Character.ruBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION,
Character.CONTROL, Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION,
Character.DECIMAL_DIGIT_NUMBER, Character.ENCLOSING_MARK, Character.END_PUNCTUATION,
Character.FORMAT, Character.LETTER_NUMBER, Character.LINE_SEPARATOR,
Character.LOWERCASE_LETTER, Character.MATH_SYMBOL, Character.MODIFIER_SYMBOL,
Character.NON_SPACING_MARK, Character.OTHER_LETTER, Character.OTHER_NUMBER,
Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL, Character.PARAGRAPH_SEPARATOR,
Character.PRIVATE_USE, Character.SPACE_SEPARATOR, Character.START_PUNCTUATION,
Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
Character.UPPERCASE_LETTER };
String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control",
"Currency symbol", "Dash punctuation", "Decimal digit number", "Enclosing mark",
"End punctuation", "Format", "Letter number", "Line separator", "Lowercase letter",
"Math symbol", "Modifier symbol", "Non spacing mark", "Other letter", "Other number",
"Other punctuation", "Other symbol", "Paragraph separator", "Private use",
"Space separator", "Start punctuation", "Surrogate", "Titlecase letter", "Unassigned",
"Uppercase letter" };
int type = Character.getType(c);
for (int i = 0; i < types.length; i++)
if (type == types[i]) {
System.out.println("Type name = " + typeNames[i]);
break;
}
System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}
}
Character: toString()
public class Main {
public static void main(String args[]) {
Character a = new Character("a");
Character a2 = new Character("a");
Character b = new Character("b");
int difference = a.rupareTo(b);
if (difference == 0) {
System.out.println("a is equal to b.");
} else if (difference < 0) {
System.out.println("a is less than b.");
} else if (difference > 0) {
System.out.println("a is greater than b.");
}
System.out.println("a is " + ((a.equals(a2)) ? "equal" : "not equal")
+ " to a2.");
System.out.println("The character " + a.toString() + " is "
+ (Character.isUpperCase(a.charValue()) ? "upper" : "lower") + "case.");
}
}
Character.UnicodeBlock.of(char c)
public class Main {
public static void main(String[] argv) throws Exception {
char ch = "\u5639";
Character.UnicodeBlock block = Character.UnicodeBlock.of(ch);
}
}
new Character(char charValue)
/*
* Output:
true
c
12
2
13245
12341234
11234.123
4.321324123412341E10
*/
public class MainClass {
public static void main(String args[]) {
Boolean bool = Boolean.valueOf("true");
Character c = new Character("c");
Byte b = Byte.valueOf("12");
Short s = Short.valueOf("2");
Integer i = Integer.valueOf("13245");
Long l = Long.valueOf("12341234");
Float f = Float.valueOf("11234.1234");
Double d = Double.valueOf("43213241234.123412341234");
System.out.println(bool);
System.out.println(c);
System.out.println(b);
System.out.println(s);
System.out.println(i);
System.out.println(l);
System.out.println(f);
System.out.println(d);
}
}