English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Conversion de la chaîne en octets dans un programme Java

La méthode convertit une chaîne en octets. Pour commencer, nous allons en créer une.valueOf()La méthode convertit une chaîne en octets. Pour commencer, nous allons en créer une.

String str = "65";

Maintenant, utilisez cettevalueOf()La méthode convertit une chaîne en octets.

byte res = Byte.valueOf(str);

Voyons un exemple complet.

Exemple

public class Demo {
   public static void main(String[] args) {
      String str = "65";
      System.out.println("String: "+str);
      byte res = Byte.valueOf(str);
      System.out.println("Byte: "+res);
   }
}

Résultat de la sortie

String: 65
Byte: 65