Byte — 바이트 래퍼 클래스

Byte — 바이트 래퍼 클래스

Byte 클래스는 원시 타입 byte의 값을 객체로 감쌉니다. Byte 타입의 객체는 타입이 byte인 단일 필드를 포함합니다. 또한 이 클래스는 byteString으로, Stringbyte로 변환하는 여러 메서드와 그 외 바이트 처리에 유용한 상수·메서드를 제공합니다.

출처: Java API Reference

본문

이 클래스는 값 기반 클래스(value-based class)이므로, 프로그래머는 동일한 인스턴스를 서로 교환 가능하게 취급해야 하며 동기화에 인스턴스를 사용해서는 안 됩니다. 그렇게 하면 예측할 수 없는 동작이 발생할 수 있습니다. 예를 들어 향후 릴리스에서는 동기화가 실패할 수 있습니다.

public final class Byte extends Number implements Comparable<Byte>, Constable

주요 필드

public static final byte MIN_VALUE   // -128
public static final byte MAX_VALUE   // 127
public static final Class<Byte> TYPE
public static final int SIZE         // 8
public static final int BYTES        // 1

주요 메서드

public static String toString(byte b)
public static Byte valueOf(byte b)
public static byte parseByte(String s) throws NumberFormatException
public static byte parseByte(String s, int radix) throws NumberFormatException
public static Byte valueOf(String s) throws NumberFormatException
public static Byte decode(String nm) throws NumberFormatException
public byte byteValue()          // Number 변환 계열
public static int compare(byte x, byte y)
public static int compareUnsigned(byte x, byte y)
public static int toUnsignedInt(byte x)
public static long toUnsignedLong(byte x)
  • parseByte는 문자열을 원시 byte로, valueOfByte 객체로 변환합니다. 문자열이 표현할 수 있는 범위를 벗어나면 NumberFormatException을 던집니다.
  • decode0x와 같은 접두사를 포함한 문자열을 변환합니다.

더 알아보기 (Learn more)