Autobox unbox a Boolean and Character. : Autobox Unbox « Data Type « Java






Autobox unbox a Boolean and Character.

Autobox unbox a Boolean and Character.
 

public class AutoBox5 { 
  public static void main(String args[]) { 
    
    Boolean b = true; 
 
    // Below, b is auto-unboxed when used in  a conditional expression, such as an if. 
    if(b) 
        System.out.println("b is true"); 
 
    // Autobox/unbox a char. 
    Character ch = 'x'; // box a char 
    char ch2 = ch; // unbox a char 
 
    System.out.println("ch2 is " + ch2); 
  } 
}


           
         
  








Related examples in the same category

1.What is Autoboxing?
2.Type conversion (JDK1.5 Autoboxing/Unboxing)
3.Demonstrate autobox and unbox.Demonstrate autobox and unbox.
4.Autobox unbox takes place with method parameters and return values.Autobox unbox takes place with method parameters and return values.
5.Autobox unbox occurs inside expressions. Autobox unbox occurs inside expressions.
6.Autobox unbox: convertAutobox unbox: convert
7.An error produced by manual unboxing. An error produced by manual unboxing.
8.Java Autobox and UnboxJava Autobox and Unbox
9.Autobox DemoAutobox Demo
10.Autoboxing/unboxing takes place with method parameters and return values.
11.Autoboxing/unboxing occurs inside expressions.
12.Auto-unboxing allows you to mix different types of numeric objects in an expression.