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



Comments

Popular posts from this blog

How to set text for a TextView in Android using Android Studio

Download Aarogya Setu Android || Corona || India

Compromising Gmail Password is way dangerous than we think!