English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Pour convertir Byte en type de données primitives numériques, utilisez les méthodes suivantes-
byteValue() shortValue() intValue() longValue() floatValue()
D'abord, déclarons une byte.
Byte byteVal = new byte("35";
Maintenant, regardons un exemple simple de comment le convertir en type long.
long longVal = byteVal.longValue(); System.out.println(longVal);
De la même manière, vous pouvez le convertir en d'autres types de données primitives, comme dans l'exemple complet suivant-
public class Demo { public static void main(String args[]) { //byte byte byteVal = new byte("35"; byte b = byteVal.byteValue(); System.out.println(b); short shortVal = byteVal.shortValue(); System.out.println(shortVal); int intVal = byteVal.intValue(); System.out.println(intVal); long longVal = byteVal.longValue(); System.out.println(longVal); float floatVal = byteVal.floatValue(); System.out.println(floatVal); double doubleVal = byteVal.doubleValue(); System.out.println(doubleVal); } }
Résultat de la sortie
35 35 35 35 35.0 35.0