Skip to content

Its a casting MAP to illiterate, how to cast a java primitive data type to another one easily by examples.

Notifications You must be signed in to change notification settings

ahmed-nabil-elagder/java-casting-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

java-casting-map

Its an easy MAP to illiterate, how to cast a java primitive data type to another one by examples
Supported Java Primitive Data Types
byte, short, int, long, float, double, boolean, char in addition to String.
You can click on any cell of below table map to show the code example.

Casting Map

From=>To byte short int long float double boolean char String
byte - By Default By Default By Default By Default By Default INVALID (char) byteVar; //ASCII_Char String.valueOf(byteVar); or
Byte.toString(byteVar); or
By Concatenation
short (byte) shortVar; - By Default By Default By Default By Default INVALID (char) shortVar; //ASCII_Char String.valueOf(shortVar); or
Short.toString(shortVar); or
By Concatenation
int (byte) intVar; (short) intVar; - By Default By Default By Default INVALID (char) intVar; //ASCII_Char String.valueOf(intVar); or
Integer.toString(intVar); or
By Concatenation
long (byte) longVar; (short) longVar; (int) longVar; - By Default By Default INVALID (char) longVar; //ASCII_Char String.valueOf(longVar); or
Long.toString(longVar); or
By Concatenation
float (byte) floatVar; (short) floatVar; (int) floatVar; (long) floatVar; - By Default INVALID (char) floatVar; //ASCII_Char String.valueOf(floatVar); or
Float.toString(floatVar); or
By Concatenation
double (byte) doubleVar; (short) doubleVar; (int) doubleVar; (long) doubleVar; (float) doubleVar; - INVALID (char) doubleVar; //ASCII_Char String.valueOf(doubleVar); or
Double.toString(doubleVar); or
By Concatenation
boolean INVALID INVALID INVALID INVALID INVALID INVALID - INVALID String.valueOf(booleanVar); or
Boolean.toString(booleanVar); or
By Concatenation
char (byte) charVar; //ASCII_Number or
(byte) (charDigitVar-'0'); //Digit_Number
(short) charVar; //ASCII_Number or
(short) (charDigitVar-'0'); //Digit_Number
By Default //ASCII_Number or
(charDigitVar-'0'); //Digit_Number
By Default //ASCII_Number or
(charDigitVar-'0'); //Digit_Number
By Default //ASCII_Number or
(charDigitVar-'0'); //Digit_Number
By Default //ASCII_Number or
(charDigitVar-'0'); //Digit_Number
INVALID - String.valueOf(charVar); or
Char.toString(charVar); or
By Concatenation
String Byte.parseByte(stringVar); Short.parseShort(stringVar); Integer.parseInt(stringVar); Long.parseLong(stringVar); Float.parseFloat(stringVar); Double.parseDouble(stringVar); Boolean.parseBoolean(stringVar); stringVar.charAt(index); -

Primitive Data Types - Values Range

- size Internal Implementation Default Value Minimum value Maximum value
byte 8 bit
(1 byte)
Two's complement integer. 0 -128 127 2^7
short 16 bit
(2 bytes)
Two's complement integer. 0 -32,768 32,767 2^15
int 32 bit
(4 bytes)
Two's complement integer. 0 -2,147,483,648 2,147,483,647 2^31
long 64 bit
(8 bytes)
Two's complement integer. 0L
0l
-9,223,372,036,854,770,000 9,223,372,036,854,770,000 2^63
float 32 bit
(4 bytes)
Single-precision 32-bit/IEEE 754 floating point. 0.0F
0.0f
1.4E-45 3.4028235E38
double 64 bit
(8 bytes)
Double-precision 64-bit/IEEE 754 floating point. 0.0D
0.0d
4.9E-324 1.7976931348623157E308
boolean VM dependent VM dependent, to store either true of false false
char 16 bit
(2 bytes)
Single 16-bit Unicode character. '\u0000' \u0000' (or 0) \uffff' (or 65,535)
String null

About

Its a casting MAP to illiterate, how to cast a java primitive data type to another one easily by examples.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages