我遇到了一些具有以下内容的代码:
String foo = getvalue("foo");
if (StringUtils.isBlank(foo))
doStuff();
else
doOtherStuff();
Run Code Online (Sandbox Code Playgroud)
这看起来在功能上等同于以下内容:
String foo = getvalue("foo");
if (foo.isEmpty())
doStuff();
else
doOtherStuff();
Run Code Online (Sandbox Code Playgroud)
两者(org.apache.commons.lang3.StringUtils.isBlank和java.lang.String.isEmpty)之间有区别吗?
可能重复:
|之间的区别是什么 和|| 在Java?
&和&&的区别
我只是想知道&和&&之间的区别是什么?
几天我写了一个if声明的条件看起来像:
if(x < 50 && x > 0)
Run Code Online (Sandbox Code Playgroud)
但是,我改变了&&只是&并没有表现出错误.有什么不同?
示例:我编译了这个简单的程序:
package anddifferences;
public class Main {
public static void main(String[] args) {
int x = 25;
if(x < 50 && x > 0) {
System.out.println("OK");
}
if(x < 50 & x > 0) {
System.out.println("Yup");
}
}
}
Run Code Online (Sandbox Code Playgroud)
它印有"OK"和"Yup".如果它们都起作用,那么我使用哪一个呢?
我的方法采用Date对象.我传递一个空值.如何检查(日期日期)日期是否为空.我是Stackoverflow中的新手,如果问题不是很好,请不要低估帖子.
在一次采访中,我的采访者问我:
如果用以下代码中的&替换&&,会出现什么问题:
String a=null; if (a!=null && a.length()>10) {...}
Run Code Online (Sandbox Code Playgroud)