Wrapper class

coding by 스플릿·2022년 1월 5일
0

Java1

목록 보기
43/44

기본형을 객체로 다뤄야 하는 경우에 사용한다.
( ex. 매개변수로 객체를 요구할 때, 객체간의 비교를 할 때 )

기본형래퍼클래스생성자
booleanBooleanBoolean(boolean value)
Boolean(String s)
charCharacterCharacter(char value)
byteByteByte(byte value)
Byte(String s)
shortShortShort(short value)
Short(String s)
intIntegerInteger(int value)
Integer(String s)
longLongLong(long value)
Long(String s)
floatFloatFloat(float value)
Float(String s)
doubleDoubleDouble(double value)
Double(String s)
public class Main{
    public static void main(String[] args) {
        Integer i = new Integer(100);
        Integer i2 = new Integer(100);
        //래퍼클래스 비교
        System.out.println("i == i2"+ (i==i2));
        System.out.println("i.equals(i2) = " + (i.equals(i2)));
        System.out.println("i.compareTo(i2) = " + (i.compareTo(i2)));
        //래퍼클래스가 가지고 있는 상수
        System.out.println("MAX+_VALUE = "+Integer.MAX_VALUE);
        System.out.println("MIN+_VALUE = "+Integer.MIN_VALUE);
        System.out.println("SIZE = "+Integer.SIZE+"bits");
        System.out.println("BYTES = "+Integer.BYTES+"bytes");
        System.out.println("TYPE = "+Integer.TYPE);
    }
}
/* 출력 :
i == i2false
i.equals(i2) = true
i.compareTo(i2) = 0
MAX+_VALUE = 2147483647
MIN+_VALUE = -2147483648
SIZE = 32bits
BYTES = 4bytes
TYPE = int
 */

0개의 댓글