English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Short를 숫자 원시 데이터 타입으로 변환하려면 다음 메서드를 사용하세요-
byteValue() shortValue() intValue() longValue() floatValue()
먼저, Short를 선언해 보겠습니다.
Short shortObj = new Short("40);
이제, long 타입으로 변환하는 간단한 예제를 보겠습니다.
long val5 = shortObj.longValue(); System.out.println("Long: "+val5);
같은 방식으로, 다른 원시 데이터 타입으로 변환할 수 있습니다. 다음과 같은 전체 예제를 참고하세요.
public class Demo { public static void main(String []args) { Short shortObj = new Short("40); byte val1 = shortObj.byteValue(); System.out.println("Byte: "+val1); int val2 = shortObj.intValue(); System.out.println("Int: "+val2); float val3 = shortObj.floatValue(); System.out.println("Float: "+val3); double val4 = shortObj.doubleValue(); System.out.println("Double: "+val4); long val5 = shortObj.longValue(); System.out.println("Long: "+val5); } }
출력 결과
Byte: 40 Int: 40 Float: 40.0 Double: 40.0 Long: 40