关于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 + "正确,校验通过~~~");
。。。