inblog logo
|
jjack1
    Java

    [JAVA] 17. 제네릭 & Wrapper & 컬렉션 & 오브젝트 Ⅱ. Wrapper 클래스

    최재원's avatar
    최재원
    Feb 18, 2025
    [JAVA] 17. 제네릭 & Wrapper & 컬렉션 & 오브젝트 Ⅱ. Wrapper 클래스
    Contents
    1. wrapper클래스를 사용해 null 저장해보기2. 문자 → 숫자로 타입 변경해보기
    ❗
    랩퍼 클래스
    • Integer
    • Long
    • Double
    wrapper를 쓰면 null을 저장할 수 있다.
    wrapper를 쓰면 함수를 사용할 수 있다.
    Long a = 10L;

    1. wrapper클래스를 사용해 null 저장해보기

    package ex17; class User { private Long no; private String name; private Integer money; public User(Long no, String name, Integer money) { this.no = no; this.name = name; this.money = money; } public Long getNo() { return no; } public String getName() { return name; } public Integer getMoney() { return money; } }; // 참조자료형만 null을 넣을 수 있다. public class Wrap01 { public static void main(String[] args) { User user = new User(1L, "이름", null); } }

    2. 문자 → 숫자로 타입 변경해보기

    package ex17; public class Wrap02 { public static void main(String[] args) { String s1 = "10"; Integer i1 = Integer.parseInt(s1); // 문자 -> 숫자 Double d1 = Double.parseDouble(s1); Integer i2 = 20; String s2 = i2 + ""; // 숫자 -> 문자 String s3 = Integer.toString(i2); } }
    Share article

    jjack1

    RSS·Powered by Inblog