[java] 형변환
int to String
1
2
String str = Integer.toString(i);
String str = "" + i;
String to int
1
2
int i = Integer.parseInt(str);
int i = Integer.valueOf(str).intValue();
double to String
1
String str = Double.toString(d);
long to String
1
String str = Long.toString(l);
float to String
1
String str = Float.toString(f);
String to double
1
double d = Double.valueOf(str).doubleValue();
String to long
1
2
long l = Long.valueOf(str).longValue();
long l = Long.parseLong(str);
String to float
1
float f = Float.valueOf(str).floatValue();
decimal to binary
1
String binstr = Integer.toBinaryString(i);
decimal to hexadecimal
1
2
3
String hexstr = Integer.toString(i, 16);
String hexstr = Integer.toHexString(i);
Integer.toHexString(0x10000 | i).substring(1).toUpperCase();
hexadecimal(String) to int
1
2
int i = Integer.valueOf("B8DA3", 16).intValue();
int i = Integer.parseInt("B8DA3", 16);
ASCII Code to String
1
String char = new Character((char)i).toString();
Integer to ASCII Code
1
int i = (int) c;
Integer to boolean
1
boolean b = (i != 0);
boolean to Integer
1
int i = (b) ? 1 : 0;
This post is licensed under CC BY 4.0 by the author.