본문 바로가기

B1:기초 Basement

Wrapping a primitive

반응형

Wrapping a primitive

Boolean
Character
Byte
Short
Integer
Long
Float
Double

wrapping a value

int i = 288
Integer iWrap = new Integer(i);

unwrapping a value

int unWrapped = iWrap.intValue();

Head First Java, 2nd Edition, p.287

Autoboxing
In Java 5.0, the conversion from primitive to wrapper object automatically.

public void doNumsNewWay() {
  ArrayList<Integer> listOfNumbers = new ArrayList<Integer>();
  listOfNumbers.add(3);
  int num = listOfNumbers.get(0);
}

Head First Java, 2nd Edition, p.289

Wrappers have static utility methods

String s = "2";
int x = Integer.parseInt(s);
반응형