[Java] Java Combining search types that you often search

less than 1 minute read

Summary of type conversions I often search for

Type conversion between numeric types

int type → double type

int num = 3;
double number = (double)num;

double type → int type

double num = 3;
int number = (int)num;

Numeric types (long etc.) can be converted by adding ** (type to be converted) ** before the variable to be type-converted.

Type conversion from number type to character type

int type → String type

int num = 3;
String number = Integer.toString(num);

double type → String type

double num = 3.0;
String number = Double.toString(num);

Type conversion from character type to numeric type

String type → int type

String text = "123";
int number = Integer.parseInt(text);

String type → double type

String text = "123";
int number = Double.parseDouble(text);

Reference site

Types and type conversion methods other than the above. [Java] Converting String type to int type