Variable Casting in Java
Example:
String number;
int number;
double number;
float number;
Casting Variable to String:
toString();
String stringNum=number.toString();
this method can be used for casting int,double,float to a String.
Casting Variable to int:
Integer.parseInt(variableName);
int num = Integer.parseInt(number);
Casting Variable to double:
Double.parseDouble(variableName);
double num = Double.parseDouble(number);
Casting Variable to float:
Float.parseFloat(variableName);
float num = Float.parseFloat(number);
*there are other methods too
String number;
int number;
double number;
float number;
Casting Variable to String:
toString();
String stringNum=number.toString();
this method can be used for casting int,double,float to a String.
Casting Variable to int:
Integer.parseInt(variableName);
int num = Integer.parseInt(number);
Casting Variable to double:
Double.parseDouble(variableName);
double num = Double.parseDouble(number);
Casting Variable to float:
Float.parseFloat(variableName);
float num = Float.parseFloat(number);
*there are other methods too
Comments
Post a Comment