Java Characters

 To store a single a single character we use char data type. The character has to be surrounded by single quotes, for example 'x'.

To create a character data type we do the following 

char sex = 'm';

char sex = 'f';

m and f refer to male and female 

Character Methods

Character wrapper class has some important methods that can be used to work with char data type.

toString(char char);

This method takes character value and returns a String object , which is, a one-character string.

String myChar=Character.toString('x');

System.out.println(myChar);


toLowerCase(char c);

This method takes in argumment of type char and return it to Lower case.

System.out.println(toLowerCase('c'));

toUpperCase(char c);

This method takes in argumment of type char and return it to upper case.

System.out.println(toUpperCase('c');

isLetter(char ch);

This method takes in char argument and returns a Boolean whether is the argument true or not.

public class CharTest {

   public static void main(String args[]) {

      System.out.println(Character.isLetter('#'));

      System.out.println(Character.isLetter('x'));

      

   }

}

Previous Post Next Post

Welcome, New Friend!

We're excited to have you here for the first time!

Enjoy your colorful journey with us!

Welcome Back!

Great to see you Again

If you like the content share to help someone

Thanks

Contact Form