Sunday, 15 July 2012

Java boolean to short

The data type boolean is incompatible for converting into any other data type. That is, a boolean value cannot be converted into any other data type like char, int, double etc. The maximum permitted is one boolean can be assigned to another boolean.

Following are not permitted.

boolean b = true;
       short x = b;             // error, boolean to short

       short x = 10;
       boolean y = x;          // error, short to boolean

       boolean b = true;
       char ch = b;           // error, boolean to char

       char ch = 'A';
       boolean b =ch;         // error, char to boolean

Following is permitted (boolean assignment).



boolean b = true;
       boolean b1 = b;            // permitted
       System.out.println(b1);    // prints true


The keyword boolean is used in comparison operations.


       int x = 10;
       int y = 20;
       boolean b = (x == y);
       System.out.println(b);   // prints false


Your one stop destination for all data type conversions



byte TOshortintlongfloatdoublecharboolean
short TObyteintlongfloatdoublecharboolean
int TObyteshortlongfloatdoublecharboolean
float TObyteshortintlongdoublecharboolean
double TObyteshortintlongfloatcharboolean
char TObyteshortintlongfloatdoubleboolean
boolean TObyteshortintlongfloatdoublechar

String and data type conversions




String TO
byte
short
int
long
float
double
char
boolean
byte
short
int
long
float
double
char
boolean
TO String






No comments:

Post a Comment

There was an error in this gadget