why StringUtils.isEmtpy(s)? null:s
is slower than !StringUtils.isEmtpy(s)? s:null
? in my test, the later one is 1 millisecond faster than first one.
test:
public static void main(String[] args) {
List<String> list = new ArrayList<String>(Arrays.asList("a", "a", "a", "a", "a", null, "a"));
Long start1 = System.nanoTime();
for (String s : list
) {
String s1 = isEmpty(s) ? null : s;
}
Long end1 = System.nanoTime();
System.out.println("null in fisrt: " + (end1 - start1));
Long start2 = System.nanoTime();
for (String s : list
) {
String s2 = !isEmpty(s) ? s : null;
}
Long end2 = System.nanoTime();
System.out.println("null in second: " + (end2 - start2));
}
//output null in fisrt: 98600 null in second: 8200