One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man

Thursday, February 3, 2011

java - Methods to manipulate characters



I will give you examples to get a clear idea about each and every method


1. isDigit()                                 - check whether the character is a digit or not
2. isLetter()                               - check whether the chatacter is a letter or not
3. isLowerCase()                       - check whether the character is a lowercase or not
4. isUpperCase()                       - check whether the character is a uppercase or not
5. toLowerCase()                      - convert the uppercase character to lowercase character
6. toUpperCase()                      - convert the Lowercase character to Uppercase character
7. isWhiteSpace()                     -  check whether the character is a space, tab or newline or not
8. isSpaceChar()                       - check whether the character is a space or not


01)  isDigit() and isLetter()


class hsp{
public static void main(String args[]){
System.out.println(Character.isDigit('a'));
System.out.println(Character.isDigit('2'));
System.out.println(Character.isLetter('a'));
System.out.println(Character.isLetter('2'));
}
}


you have to use covering class to use these methds


Character.isDigit('a')
Character.isLetter('a')


output : 














02)  isLowerCase() and isUpperCase()


class hsp{
public static void main(String args[]){
System.out.println(Character.isLowerCase('a'));
System.out.println(Character.isLowerCase('A'));
System.out.println(Character.isLowerCase('2'));
System.out.println(Character.isUpperCase('a'));
System.out.println(Character.isUpperCase('A'));
System.out.println(Character.isUpperCase('2'));
}
}


Output:
















03)  toLowerCase() and toUpperCase()


class hsp{
public static void main(String args[]){
System.out.println(Character.toLowerCase('a'));
System.out.println(Character.toLowerCase('A'));
System.out.println(Character.toLowerCase('2'));
System.out.println(Character.toUpperCase('a'));
System.out.println(Character.toUpperCase('A'));
System.out.println(Character.toUpperCase('2'));
}
}


Output:
















04)  isSpaceChar()


class hsp{
public static void main(String args[]){
System.out.println(Character.isSpaceChar('a'));
System.out.println(Character.isSpaceChar('A'));
System.out.println(Character.isSpaceChar('2'));
System.out.println(Character.isSpaceChar('\t'));
System.out.println(Character.isSpaceChar(' '));
  }
}


Output:
















05)  isWhitespace()


class hsp{
public static void main(String args[]){
System.out.println(Character.isWhitespace('a'));
System.out.println(Character.isWhitespace('A'));
System.out.println(Character.isWhitespace('2'));
System.out.println(Character.isWhitespace('\t'));
System.out.println(Character.isWhitespace('\n'));
System.out.println(Character.isWhitespace(' '));
}
}


Remember the "space" word in the "isWhitespace()" keyword is lower case.


Output:



2 comments: