java.lang.Character
class having some useful methods. Character class is a wrapper class for character data type.
Following
function return type is boolean
isUpperCase()
– Return true if given character is in Uppercase or else return false.
isLowerCase()
– Return true if given character is in Lowercase or else return false.
isDigit()
– Return true if given character is a digit or else return false.
isLetter()
– Return true if given character is a alphabet or else return false.
isWhitespace()
– Return true if given character is whitespace or else return false.
Java
whitespace consists – space, tab (‘\t’),
form feed character (‘\r’).
toUpperCase()
– Returns the given character in uppercase form.
toLowerCase()
– Returns the given character in Lowercase form.
//Character Class
public class Character_Fun
{
public static void main(String
args[])
{
char ch='a';
System.out.println("\n\tCharacter '"+ch+"' is a Letter? -
"+Character.isLetter(ch));
ch='a';
System.out.println("\tCharacter '"+ch+"' is Lowercase? -
"+Character.isLowerCase(ch));
ch='A';
System.out.println("\tCharacter '"+ch+"' is Uppercase? -
"+Character.isUpperCase(ch));
ch='\t';
System.out.println("\tCharacter '"+ch+"' is WhiteSpace? -
"+Character.isWhitespace(ch));
ch='9';
System.out.println("\tCharacter '"+ch+"' is Digit? -
"+Character.isDigit(ch));
ch='a';
System.out.println("\tCharacter '"+ch+"' Convert to
Uppercase - "+Character.toUpperCase(ch));
ch='A';
System.out.println("\tCharacter '"+ch+"' Convert to Lowercase -
"+Character.toLowerCase(ch));
}
}
Output
Character 'a' is a Letter? - true
Character 'a' is Lowercase? - true
Character 'A' is Uppercase? - true
Character ' ' is
WhiteSpace? - true
Character '9' is Digit? - true
Character 'a' Convert to Uppercase - A
Character 'A'
Convert to Lowercase – a
No comments:
Post a Comment