「Java」三項演算子で文字列の値のnull判定をするサンプル
書式
条件式?値1:値2
Javaコード
package com.arkgame.study.cft;
public class JavaSange {
protected static boolean result;
public static void main(String[] args) {
String strA = null;
String strB = "arkgame.com";
funcA(strA);
funcA(strB);
}
public static void funcA(String target) {
result = (target == null) ? true : false;
System.out.println("値のnull判定結果: " + result);
}
}
package com.arkgame.study.cft;
public class JavaSange {
protected static boolean result;
public static void main(String[] args) {
String strA = null;
String strB = "arkgame.com";
funcA(strA);
funcA(strB);
}
public static void funcA(String target) {
result = (target == null) ? true : false;
System.out.println("値のnull判定結果: " + result);
}
}
package com.arkgame.study.cft; public class JavaSange { protected static boolean result; public static void main(String[] args) { String strA = null; String strB = "arkgame.com"; funcA(strA); funcA(strB); } public static void funcA(String target) { result = (target == null) ? true : false; System.out.println("値のnull判定結果: " + result); } }
実行結果
値のnull判定結果: true
値のnull判定結果: false