Java Reference
In-Depth Information
// Using the factory method - preferred
Character c2 = Character.valueOf('2');
Character c3 = Character.valueOf('ñ');
// Getting the wrapped char values
char cc1 = c1.charValue();
char cc2 = c2.charValue();
char cc3 = c3.charValue();
System.out.println("c1 = " + c1);
System.out.println("c2 = " + c2);
System.out.println("c3 = " + c3);
// Using some Character class methods on c1
System.out.println("isLowerCase c1 = " + Character.isLowerCase(cc1));
System.out.println("isDigit c1 = " + Character.isDigit(cc1));
System.out.println("isLetter c1 = " + Character.isLetter(cc1));
System.out.println("Lowercase of c1 = " + Character.toLowerCase(cc1));
// Using some Character class methods on c2
System.out.println("isLowerCase c2 = " + Character.isLowerCase(cc2));
System.out.println("isDigit c2 = " + Character.isDigit(cc2));
System.out.println("isLetter c2 = " + Character.isLetter(cc2));
System.out.println("Lowercase of c2 = " + Character.toLowerCase(cc2));
System.out.println("Uppercase of c3 = " + Character.toUpperCase(cc3));
c1 = A
c2 = 2
c3 = ñ
isLowerCase c1 = false
isDigit c1 = false
isLetter c1 = true
Lowercase of c1 = a
isLowerCase c2 = false
isDigit c2 = true
isLetter c2 = false
Lowercase of c2 = 2
Uppercase of c3 = Ñ
The Boolean Wrapper Class
An object of the Boolean class wraps a boolean . The Boolean.TRUE and Boolean.FALSE are two constants of the
Boolean type to represent boolean true and false values. You can create a Boolean object using the constructors
or the valueOf() factory method. When parsing a string, this class treats "true" (ignoring the case of all characters)
as the true and any other strings as the false . Use the valueOf() method of this class to create a Boolean object as
much as possible because it returns Boolean.TRUE or Boolean.FALSE constant instead of creating new objects. The
following snippet of code shows how to use the Boolean class. The variable name in each statement indicates the type
of boolean value ( true or false ) represented in the Boolean object.
 
Search WWH ::




Custom Search