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.

stringutils.isblank()

foo.isempty() 

returns true if, , if, length() 0.

isempty()

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

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -