Character function in Java ?

Character function in Java ?

  • 1 toUpperCase()
  • Converts the given char into uppercase form.
class Easy
{  
 public static void main(String[] args) 
 {
   System.out.println(Character.toUpperCase('a'));
   System.out.println(Character.toUpperCase('A'));
 }
}
/*
### OUTPUT ###
A
A
*/
  • 2 toLowerCase()
  • Converts the given char into lowercase form.
class Easy
{  
 public static void main(String[] args) 
 {
   System.out.println(Character.toLowerCase('a'));
   System.out.println(Character.toLowerCase('A'));
 }
}
/*
### OUTPUT ###
a
a
*/
  • 3 isLetter()
  • Used to check the given char is letter or not.
  • It returns boolean value(True/False).
  • Returns true if char is letter otherwise returns false.
class Easy
{  
 public static void main(String[] args) 
 {
   System.out.println(Character.isLetter('a')); 
   System.out.println(Character.isLetter('9'));
 }
}
/*
### OUTPUT ###
true
false
*/
  • 4 isDigit()
  • Used to check the given char is digit or not.
  • It returns boolean value(True/False).
  • Returns true if char is digit otherwise returns false.
class Easy
{  
 public static void main(String[] args) 
 {
   System.out.println(Character.isDigit('a')); 
   System.out.println(Character.isDigit('9'));
 }
}
/*
### OUTPUT ###
false
true
*/
  • 5 isUpperCase()
  • Used to check the given char is uppercase or not.
  • It returns boolean value(True/False).
  • Returns true if char is uppercase otherwise returns false.
class Easy
{  
 public static void main(String[] args) 
 {
   System.out.println(Character.isUpperCase('a')); 
   System.out.println(Character.isUpperCase('A'));
 }
}
/*
### OUTPUT ###
false
true
*/
  • 6 isLowerCase()
  • Used to check the given char is lowercase or not.
  • It returns boolean value(True/False).
  • Returns true if char is lowercase otherwise returns false.
class Easy
{  
 public static void main(String[] args) 
 {
   System.out.println(Character.isLowerCase('a')); 
   System.out.println(Character.isLowerCase('A'));
 }
}
/*
### OUTPUT ###
true
false
*/
  • 7 isWhiteSpace()
  • Used to check the given char is white space or not.
  • It returns boolean value(True/False).
  • Returns true if char is white space otherwise returns false.
class Easy
{  
 public static void main(String[] args) 
 {
   System.out.println(Character.isWhitespace(' ')); 
   System.out.println(Character.isWhitespace('A'));
 }
}
/*
### OUTPUT ###
true
false
*/
Next Post Previous Post
No Comment
Add Comment
comment url