Java-lang-boolean-tostring-boolean
提供:Dev Guides
Java.lang.Boolean.toString()メソッド
説明
- java.lang.Boolean.toString(boolean b)*は、指定されたブール値を表すStringオブジェクトを返します。 指定されたブール値がtrueの場合、文字列「true」が返され、それ以外の場合、文字列「false」が返されます。
宣言
以下は* java.lang.Boolean.toString()*メソッドの宣言です
public static String toString(boolean b)
パラメーター
*b* -変換されるブール値
戻り値
このメソッドは、指定されたブール値の文字列表現を返します。
例外
NA
例
次の例は、lang.Boolean.toString()メソッドの使用法を示しています。
package com.finddevguides;
import java.lang.*;
public class BooleanDemo {
public static void main(String[] args) {
//create 2 boolean primitives bool1, bool2
boolean bool1, bool2;
//assign values to bool1, bool2
bool1 = true;
bool2 = false;
//create 2 String's s1, s2
String s1, s2;
/**
*static method is called using class name
* assign string value of primitives bool1, bool2 to s1, s2
*/
s1 = Boolean.toString(bool1);
s2 = Boolean.toString(bool2);
String str1 = "String value of boolean primitive " +bool1+ " is " +s1;
String str2 = "String value of boolean primitive " +bool2+ " is " +s2;
//print s1, s2 values
System.out.println( str1 );
System.out.println( str2 );
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
String value of boolean primitive true is true
String value of boolean primitive false is false