「Java」関係演算子でboolean型の値を取得するサンプル

演算子
&&(論理積)、||(論理和)、!(論理否定)
Javaコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.study;
public class BooleanEnsaDemo {
public static void main(String[] args) {
String strA = "this is a test";
String strB = null;
String strC = "";
boolean resultA = (strA != null && strA.length() > 0);
boolean resultB = (strB != null && strB.length() > 0);
boolean resultC = (strC != null && strC.length() > 0);
System.out.println(resultA);
System.out.println(resultB);
System.out.println(resultC);
}
}
package com.arkgame.study; public class BooleanEnsaDemo { public static void main(String[] args) { String strA = "this is a test"; String strB = null; String strC = ""; boolean resultA = (strA != null && strA.length() > 0); boolean resultB = (strB != null && strB.length() > 0); boolean resultC = (strC != null && strC.length() > 0); System.out.println(resultA); System.out.println(resultB); System.out.println(resultC); } }
package com.arkgame.study;

public class BooleanEnsaDemo {

      public static void main(String[] args) {

            String strA = "this is a test";
            String strB = null;
            String strC = "";
            boolean resultA = (strA != null && strA.length() > 0);
            boolean resultB = (strB != null && strB.length() > 0);
            boolean resultC = (strC != null && strC.length() > 0);
            System.out.println(resultA);
            System.out.println(resultB);
            System.out.println(resultC);
      }

}

結果
true
false
false

Java

Posted by arkgame