java - which is best between string isEmpty and StringUtils.isNotBlank() -
this question has answer here:
i use following code check timing:
public static void main(string[] args) throws exception { string foo = "foo"; long start=system.currenttimemillis(); if (stringutils.isblank(foo)); long end=system.currenttimemillis(); system.out.println("isblank="+(end-start)); start=system.currenttimemillis(); if (foo!=null && !foo.isempty()); end=system.currenttimemillis(); system.out.println("sec="+(end-start)); }
the stringutils.isblank() method takes 3ms longer simple string.isempty() method. method should use?
stringutils.isblank(foo));
checks if string whitespace, empty ("") or null.
foo.isempty()
returns true if, , if, length() 0.
so if want advanced not throw npe if string null, ignore empty string (so auto trim ) use stringutils.isblank(foo));
on other hand shown performance difference have cause isempty()
see length.
its choice depending on need.
Comments
Post a Comment