判断字符串为空

String s = null;
  //System.out.println(s.isEmpty());//空指针
  s = "";
  System.out.println(s.isEmpty());//true
  s = "   ";
  System.out.println(s.isEmpty());//false
  System.out.println(s.trim().isEmpty());//true
  //考虑连接使用
  System.out.println(s!=null && !s.trim().isEmpty());

猜你喜欢

转载自blog.csdn.net/chenaimanhua/article/details/39395235