如何检查字符串不为空? [英] How to check a string is not null?

查看:56
本文介绍了如何检查字符串不为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if(string.equals(""))
{

}

如何检查字符串是否不为空?

How to check if the string is not null?

if(!string.equals(""))
{

}

推荐答案

通过 if(string!= null)

如果要检查其null还是空-您需要 if(string!= null&&!string.isEmpty())

If you want to check if its null or empty - you'd need if (string != null && !string.isEmpty())

我更喜欢使用 commons-lang StringUtils.isNotEmpty(..)

这篇关于如何检查字符串不为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆