2015년 1월 24일 토요일

[Java] int, double, long, float <->(to) string 형 변환하기

int -> string


String myString = Integer.toString(my int value)
   or
String str = "" + i

String -> int


int i = Integer.parseInt(str);
   or
int i = Integer.valueOf(str).intValue();

double -> String

String str = Double.toString(i);

String -> double

double d = Double.valueOf(str).doubleValue();

long -> String

String str = Long.toString(l);

String -> long

long l = Long.valueOf(str).longValue();
   or
long l = Long.parseLong(str);

float -> String

String str = Float.toString(f);
  
String -> float

float f = Float.valueOf(str).floatValue();

integer -> boolean

b = (i != 0);

boolean -> integer

i = (b)?1:0;

댓글 없음:

댓글 쓰기