Java new BooleanでString型からBooleanへキャストするサンプル

環境
Java 1.8
Eclipse 4.14

構文
Boolean 変数名 = new Boolean(文字列)
new Boolean(value)を使用してString型からBooleanへキャストします。
メソッドを使用されるたびに新しいBoolean objectを返します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.test;
public class ArkgameApp {
public static void main(String[] args) {
String str = "false";
Boolean res = new Boolean(str);
System.out.print("String型からBooleanへキャストする結果:" + res);
}
}
package com.arkgame.test; public class ArkgameApp { public static void main(String[] args) { String str = "false"; Boolean res = new Boolean(str); System.out.print("String型からBooleanへキャストする結果:" + res); } }
package com.arkgame.test;

public class ArkgameApp {

      public static void main(String[] args) {
            String str = "false";
            Boolean res = new Boolean(str);
            System.out.print("String型からBooleanへキャストする結果:" + res);
      }

}

実行結果
String型からBooleanへキャストする結果:false

Java

Posted by arkgame