Skip to main content

(How) can I improve the empty string check code

(How) can I improve the empty string check code below:
String s = "";
if( s != null && s.equals(""))
            System.out.println("");

Highlight all the lines below for the answer:
Use StringUtils IsEmpty() or IsBlank() methods as appropriate

String s = "";
assertEquals("Empty check", true, StringUtils.isEmpty(s));
s=null;
assertEquals("Null check", true, StringUtils.isEmpty(s));
s=" ";
assertEquals("Blank check false", false, StringUtils.isEmpty(s));

assertEquals("Blank check true", true, StringUtils.isBlank(s));

Comments