English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Questa è la nostra stringa.
String str = "L'Asia è un continente!";
Ora, usiamo l'array di byte egetBytes()
metodo per raggiungere il nostro obiettivo.
byte[] byteVal = str.getBytes();
Ora, se vogliamo ottenere la lunghezza dell'array, restituirà questa lunghezza, come mostrato nel seguente esempio completo:
public class Demo { public static void main(String args[]) { String str = "L'Asia è un continente!"; System.out.println(str); //Converti in array di byte byte[] byteVal = str.getBytes(); //Ottieni la lunghezza System.out.println(byteVal.length); } }
Risultato di output
L'Asia è un continente! 20