String to Number, String to Wrapper class

String to Number 1. Using Integer.intValue() 2. Using Integer.parseInt() 3. Using Integer.valueOf()

int i = new Integer("100").intValue();
int i2 = Integer.parseInt("100");
Integer i3 = Integer.valueOf("100");

String->Primitive

String->Wrapper class

byte b = Byte.parseByte("100");

short s = Short.parseShort("100");

int i = Integer.parseInt("100");

long l = Long.parseLong("100");

float f = Float.parseFloat("3.14");

double d = Double.parseDouble("3.14");

Byte b = Byte.valueOf("100");

Short s = Short.valueOf("100");

Integer i = Integer.valueOf("100");

Long l = Long.valueOf("100");

Float f = Float.valueOf("3.14");

Double d = Double.valueOf("3.14");

n진법의 문자열을 숫자로

int i4 = Integer.parseInt("100",2);//100(2)->4
int i5 = Integer.parseInt("100",8);//100(8)->64
int i6 = Integer.parseInt("100",16);//100(16)->256
int i7 = Integer.parseInt("FF",2);//FF(16)->255


//there is no "FF" in decimal.
//int i4 = Integer.parseInt("FF");error

Last updated