English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
È possibile creare un oggetto String in Java utilizzando un testo di stringa.
String myStr = "Amit";
Un altro modo per creare un oggetto String è utilizzare la parola chiave new.
String myStr = new String("Hello!");
Usiamo il primo metodo per creare un oggetto String.
String str = "true";
Ora, usando ilvalueOf()
Il metodo converte un oggetto String in un oggetto Boolean. Lo abbiamo già utilizzato su un oggetto Boolean.
Boolean bool = Boolean.valueOf(str);
Ora vediamo un esempio completo per mostrare come convertire un oggetto String in un oggetto Boolean.
public class Demo { public static void main(String[] args) { String str = "true"; //Conversione Boolean bool = Boolean.valueOf(str); System.out.println(bool); } }
Risultato di output
Verità