Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Tags
more
Archives
Today
Total
관리 메뉴

선진이네

[JAVA] parseInt() VS valueOf() 본문

Language/JAVA

[JAVA] parseInt() VS valueOf()

악마선진 2022. 11. 10. 10:34
int a = Integer.valueOf("1234");
int b = Integer.parseInt("1234");
System.out.println("a = [" + a + "]");
System.out.println("b = [" + b + "]");

위와 같이 a, b에 동일한 문자열인 "1234"를 Integer 형태로 변환한 결과는 다음과 같다.

a = [1234]     b = [1234]

결과 상으로 본다면 동일한 값을 리턴하는 것을 확인할 수 있다.

그러나 둘은 확연히 다른 차이가 존재한다. 그를 알아보려 한다.

 

parseInt가 리턴하는 결과값은 int 형으로 기본 자료형 (Primitive type)이다.

valueOf가 리턴하는 결과값은 new Integer()로 객체 형태이다.

 

https://sunjinb-study-log.tistory.com/entry/JAVA-int%EB%9E%91-Integer%EB%8A%94-%EB%AD%90%EA%B0%80-%EB%8B%A4%EB%A5%B8%EA%B1%B8%EA%B9%8C

 

[JAVA] int랑 Integer는 뭐가 다를까

코딩 테스트 준비를 하면서 int랑 Integer의 차이를 알고싶어 정리를 딱 한번만 하고 가려한다. 쉽게 말해서 int는 Primitive 자료형이고, Integer는 Wrapper 클래스이다. int는 Primitive 자료형(long, float, double

sunjinb-study-log.tistory.com

 

위의 글처럼 int 와 Integer는 분명한 차이가 있다.

따라서 분명한 차이점을 인지하고 기본 자료형, 객체의 필요성에 따른 메소드를 사용해야 할 것이다.