isEmpty(); and isBlank();

 package com.company;


public class Main {

public static void main(String[] args) {
String a = " ";
System.out.println(a.isEmpty());
System.out.println(a.isBlank());
String b = "";
System.out.println(b.isEmpty());
System.out.println(b.isBlank());
}
}
Outcome:
false
true
true
true

a - is not empty despite the fact that there is a space inside it. Any character inside string
means it is not empty. 
a - is blank, because it does not have any character and has only space inside it.
b - is empty, because it does not have any character. That is why it is true.
b - is blank, because it does not have any character.

Комментарии

Популярные сообщения из этого блога

Lesson1: JDK, JVM, JRE

SE_21_Lesson_11: Inheritance, Polymorphism

SE_21_Lesson_9: Initialization Blocks, Wrapper types, String class