原文詳解:Java字符串空與過濾處理
原文鏈接: http://licocom.com/archives/1162
常用java字符串空處理,與字符串空過濾處理
/**
* 判斷是否是空字符串 null和"" 都返回 true
* @author
* @param s
* @return
*/
public static boolean isEmpty(String s) {
if (s != null && !s.equals("")) {
return false;
}
return true;
}
/**
* 轉化爲String時過濾空
* @param o
* @return
*/
public static String formatEmpty(Object o){
if(o == null){
return "";
}else{
return o.toString();
}
}
面向需求開發,記錄學習之路。