📙 자바 Java

[자바/Java] String to int / int to String 형변환

핑크빛연어 2021. 5. 12. 14:53

 

 

 String -> int (String to int)

 

 

Integer.parseInt(str) 사용


String str = "123";
int intStr = Integer.parseInt(str);
System.out.println("str to int :: "+intStr);

 

 

 

 int -> String (int to String)

 

String.valueOf(num) 사용


int num = 123;
String strNum = String.valueOf(num);
System.out.println("int to str :: "+strNum);

 

 

 

728x90
반응형