Logo

Programming-Idioms

  • PHP
  • C++
  • Python
  • JS
  • Java

Idiom #320 Test if string is empty

Set b to true if the string s is empty, false otherwise

boolean b = s.intern() == "";

If you're comparing a String reference to a String literal, you can use the equality operator if you "intern" the reference.
boolean b = s.equals("");
b = s.empty();
b = s == ''
b = not s
let b = !!s
#include <string.h>
bool b = !strlen(s);

C23 bool

New implementation...
< >
programming-idioms.org