關於TextUtils.isEmpty(String)與String.isEmpty()與String==null的區別
首先看源碼
1. TextUtils.isEmpty(String)在httpcore-4.4.11.jar/org/apache/http/util/TextUtils.class
if (TextUtils.isEmpty(search_from)) {
點擊查看源碼,TextUtils.isEmpty(要判斷的字符串) 會對 null 和長度""進行判斷
JSONObject不可以調用此方法,但可以調用isEmpty()方法
package org.apache.http.util;
public final class TextUtils {
public TextUtils() {
}
public static boolean isEmpty(CharSequence s) {
if (s == null) {
return true;
} else {
return s.length() == 0;
}
}
2. if (search_from.isEmpty()) 是在src.zip/java/lang/String.java下
String.isEmpty()判斷長度是否爲0,也就是""
public boolean isEmpty() {
return value.length == 0;
}
3. if (search_from == null) {
|
if (track_info.containsKey("search_from") && !arg1.matches("xx\\d*.selectbutton_\\d*")) {
//獲取search_from的value值
String search_from = track_info.getString("search_from");
// search_from爲空判斷
if (TextUtils.isEmpty(search_from)) {
// if (search_from.isEmpty()) {
System.err.println(searchFromError + "值爲空");
} else {
if (Integer.parseInt(search_from) <= 0 || Integer.parseInt(search_from) > 20) {
System.err.println(searchFromError + "值錯誤");
}
if (search_from == null) {
System.err.println("search_from爲null," + searchFromError);
}
}
}
// System.out.println(searchFromRight + "正確,校驗通過~~~");
。。。