Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

char primitive

KishorM's picture

Convert upper case char to lower case char example

5
Your rating: None Average: 5 (1 vote)
  1. /*
  2.  * Convert upper case char to lower case char example.
  3.  */
  4.  
  5. public class UpperCharToLowerChar {
  6.  
  7.  public static void main(String args[]){
  8.  
  9.   char upperCaseCh = 'A';
  10.  
  11.   /*
  12.    * to convert upper case char to lower case use static toLowerCase method
  13.    * of Character class.
  14.    */
  15.  
  16.   char lowerCaseCh = Character.toLowerCase(upperCaseCh);
  17.  
KishorM's picture

Convert lower case char to upper case char example

1
Your rating: None Average: 1 (1 vote)
  1. /*
  2.  * Convert lower case char to upper case char example.
  3.  */
  4.  
  5. public class LowerCharToUpperChar {
  6.  
  7.  public static void main(String args[]){
  8.  
  9.   char lowerCaseCh = 'd';
  10.  
  11.   /*
  12.    * to convert lower case char to upper case use static toUpperCase method
  13.    * of Character class.
  14.    */
  15.  
  16.   char upperCaseCh = Character.toUpperCase(lowerCaseCh);
  17.  
Megha's picture

Convert String to char array example

2
Your rating: None Average: 2 (3 votes)
  1. /*
  2.  * Convert String to char array example. Program to convert String object
  3.  * to array of character.
  4.  */
  5.  
  6. public class StringToCharArray {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   String str = "Hello world";
  11.  
  12.   //to convert string to char array, use toCharArray method of String
  13.   char[] ch = str.toCharArray();
  14.  
Megha's picture

Convert String to char example

0
Your rating: None
  1. /*
  2.  * Convert String to char example. Program to convert String
  3.  * to char.
  4.  */
  5.  
  6. public class StringToChar {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   String strCh = "h";
  11.    
  12.   //to convert String to char use charAt method of String class.
  13.   char ch = strCh.charAt(0);
  14.  
  15.   System.out.println("String converted to char: " + ch);
  16.  
  17.  }
  18.  
  19. }
Megha's picture

Convert char to String example

0
Your rating: None
  1. /*
  2.  * Convert char to String example. Program to convert char
  3.  * to String.
  4.  */
  5.  
  6. public class CharToString {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   char ch = 'e';
  11.    
  12.   //to convert char to String use static toString method of Character class.
  13.   String strCh = Character.toString(ch);
  14.    
  15.   System.out.println("char converted to String: " + strCh);
Ramasubramaniam's picture

Convert char to Integer example

1
Your rating: None Average: 1 (2 votes)
  1. /*
  2.  * Convert char to Integer example. Program to convert char
  3.  * to Integer wrapper number.
  4.  */
  5.  
  6. public class CharToInteger {
  7.  
  8.  public static void main(String args[]){
  9.    
  10.    char ch = 'a';
  11.      
  12.    //user Integer constructor
  13.    Integer iObj = new Integer((int)ch);
  14.      
  15.    System.out.println("char converted to Integer: " + iObj);
  16.    
  17.  }
  18. }
Ramasubramaniam's picture

Convert char to int ASCII example

0
Your rating: None
  1. /*
  2.  * Convert char to int ASCII example. Program to convert char
  3.  * to int ASCII number.
  4.  */
  5.  
  6. public class CharToInt {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   char ch = 'a';
  11.    
  12.   //cast the character to convert it to int
  13.   int asciiCode = (int)ch;
  14.    
  15.   System.out.println("char converted to int ascii code: " + asciiCode);
  16.  
  17.  }
  18.  
  19. }
Syndicate content