Java에서 Int가 Null인지 확인
Haider Ali
2023년10월12일
Java
Java Int

이 가이드에서는 Java에서 int
가 null인지 확인하는 방법을 배웁니다. 이 개념을 이해하려면 int
데이터 유형에 대한 기본적인 이해가 필요합니다. 뛰어들어봅시다.
Java에서 int
가 Null이 될 수 있습니까?
우리가 먼저 이해해야 할 한 가지는 int
가 원시 데이터 유형이라는 것입니다. 이러한 데이터 유형은 기본적으로 메모리에 이진 형식으로 데이터를 저장합니다. 즉, null이 될 수 없습니다. null 값에 대해 int
를 확인할 수는 없습니다. 반면에 null 값을 가질 수 있는 객체인 Integer
와 혼동할 수 없습니다. 정수
는 개발자가 int
와 관련된 더 많은 기능을 가질 수 있도록 하는 int
의 래퍼 클래스입니다.
public class Main {
public static void main(String[] args) {
int id = 0; // Primitve DataTypes..
Integer ID = new Integer(5);
System.out.println("Primitive integer : " + id);
// we cannot check for Null Property
System.out.println("Integer Object : " + ID);
// We can check for Null Property..
if (ID == null) {
System.out.println("Integer Is Null");
} else {
System.out.println("Integer Is Not Null");
}
}
}
출력:
Primitive integer : 0
Integer Object : 5
Integer Is Not Null
위의 예에서 볼 수 있듯이 int
는 null일 수 없습니다. 반면 Integer
는 null 속성을 확인할 수 있는 객체입니다.
튜토리얼이 마음에 드시나요? DelftStack을 구독하세요 YouTube에서 저희가 더 많은 고품질 비디오 가이드를 제작할 수 있도록 지원해주세요. 구독하다
작가: Haider Ali
Haider specializes in technical writing. He has a solid background in computer science that allows him to create engaging, original, and compelling technical tutorials. In his free time, he enjoys adding new skills to his repertoire and watching Netflix.
LinkedIn