기본 자료형인 int를 리턴
class stringToInt {
public static void main(String[] args) {
String str = 123;
int num = Integer.parseInt(str);
System.out.println(num); // 결과 : 123
}
}
객체인 Integer Object를 리턴
class stringToInt {
public static void main(String[] args) {
String str = 123;
int num = Integer.valueOf(str);
System.out.println(num); // 결과 : 123
}
}
📍 기본 int 가 필요하면 parseInt()를 Integer 래퍼 객체가 필요하면 valueOf()를 사용하면 된다.
class intToString {
public static void main(String[] args) {
int num = 123;
String str = Integer.toString(num);
System.out.println(str); // 결과 : 123
}
}
class intToString {
public static void main(String[] args) {
int num = 123;
String str = Integer.valueOf(num);
System.out.println(str); // 결과 : 123
}
}
class intToString {
public static void main(String[] args) {
int num = 123;
String str = num + "";
System.out.println(str); // 결과 : 123
}
}
[출처]
https://hianna.tistory.com/524
https://blog.naver.com/sthwin/221000179980