Java 中 Boolean 的字串表示形式
要獲取 Boolean 的字串表示形式,請使用 toString() 方法。
首先,我們對 Boolean 物件使用 valueOf() 方法並設定一個字串值。
Boolean val = Boolean.valueOf("false");然後使用 “toString() 方法對它進行表示。
val.toString();
讓我們看一個完整的示例,它以 Java 中的 Boolean(True 和 False)列印字串表示形式。
示例
public class Demo {
public static void main(String[] args) {
// false
Boolean val = Boolean.valueOf("false");
System.out.println("Displaying the string representation of Boolean");
System.out.println(val.toString());
// true
val = Boolean.valueOf("true");
System.out.println(val.toString());
}
}輸出
Displaying the string representation of Boolean false true
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP