Tytuł w zasadzie mówi wszystko. Zwykle testuję to obok a string == null, więc nie martwię się testem zerowym. Którego powinienem użyć?
String s = /* whatever */;
...
if (s == null || "".equals(s))
{
// handle some edge case here
}
lub
if (s == null || s.isEmpty())
{
// handle some edge case here
}
W tej notatce - czy isEmpty()nawet robi coś innego niż return this.equals("");lub return this.length() == 0;?
isEmpty()jest to tylko Java 6+.