java是否为空的判断的例子

来源:互联网 发布:电脑服务网络怎么办 编辑:程序博客网 时间:2024/06/02 04:03

写个简单的,不为空的util



package com.gy.util;import org.junit.Test;import java.util.*;public class StrUtil {   @Test   public void test(){      List list = new ArrayList();      list.add("aa");      HashMap map = new HashMap<>();      Set set = new HashSet();      System.out.println(isNull(0));   }   public static boolean isNull(Object o){      if(o==null)return true;      if(o instanceof String){         o = ((String) o).trim();         if("".equals(o)||"null".equals(o)){            return true;         }      }else if(o instanceof Collection){         if(((Collection) o).size()==0){            return true;         }      }else if(o instanceof Map){         if(((Map) o).size()==0){            return true;         }      }      return false;   }  public static boolean isNotNull(Object o){     return !isNull(o);  }}

原创粉丝点击