Skip to main content
Commonmark migration
Source Link

#Use String#isEmpty()

Use String#isEmpty()

To check if a String is empty, you could use either of these:

s.length()<1 // 12 bytes s.equals("") // 12 bytes 

However, using .isEmpty() is one byte shorter:

s.isEmpty() // 11 bytes 

Note that for Lists it's still shorter to check the size instead of using isEmpty():

l.size()<1 // 10 bytes l.isEmpty() // 11 bytes 

#Use String#isEmpty()

To check if a String is empty, you could use either of these:

s.length()<1 // 12 bytes s.equals("") // 12 bytes 

However, using .isEmpty() is one byte shorter:

s.isEmpty() // 11 bytes 

Note that for Lists it's still shorter to check the size instead of using isEmpty():

l.size()<1 // 10 bytes l.isEmpty() // 11 bytes 

Use String#isEmpty()

To check if a String is empty, you could use either of these:

s.length()<1 // 12 bytes s.equals("") // 12 bytes 

However, using .isEmpty() is one byte shorter:

s.isEmpty() // 11 bytes 

Note that for Lists it's still shorter to check the size instead of using isEmpty():

l.size()<1 // 10 bytes l.isEmpty() // 11 bytes 
Clarified that this only applies to Strings, not to Lists as well
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#Use .isEmptyString#isEmpty()

To check if a String is empty, you could use either of these:

s.length()<1 // 12 bytes s.equals("") // 12 bytes 

However, using .isEmpty() is one bybyte shorter:

s.isEmpty() // 11 bytes 

Note that for Lists it's still shorter to check the size instead of using isEmpty():

l.size()<1 // 10 bytes l.isEmpty() // 11 bytes 

#Use .isEmpty()

To check if a String is empty, you could use either of these:

s.length()<1 // 12 bytes s.equals("") // 12 bytes 

However, using .isEmpty() is one by shorter:

s.isEmpty() // 11 bytes 

#Use String#isEmpty()

To check if a String is empty, you could use either of these:

s.length()<1 // 12 bytes s.equals("") // 12 bytes 

However, using .isEmpty() is one byte shorter:

s.isEmpty() // 11 bytes 

Note that for Lists it's still shorter to check the size instead of using isEmpty():

l.size()<1 // 10 bytes l.isEmpty() // 11 bytes 
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#Use .isEmpty()

To check if a String is empty, you could use either of these:

s.length()<1 // 12 bytes s.equals("") // 12 bytes 

However, using .isEmpty() is one by shorter:

s.isEmpty() // 11 bytes