[JAVA]isBlank, isEmpty, hasText 비교하기

Macaron·2021년 8월 15일
0

개발할때 isBlank, isEmpty를 통해서 항상 null체크를 했었는데 최근 hasText를 알게되면서 세개가 어떤 차이점이 있는지 찾아보다가 충격적인 사실을 발견하게되었다.

isEmpty는 whitespace를 체크하지 않는다는 것!

null체크만 처리했어서 whitespace는 체크하지 못한다는게 큰 리스크는 아니었지만 이렇게 충격적인 사실을 알게되었다.

그리고 최근 Spring 5.3.9 버전부터 isEmpty도 deprecated 되어서 더이상 지원하지 않는다고 하니 대체로 hasText를 사용해야할듯!

정리하자면

isBlank -> "", null, whitespace 체크
isEmpty -> "", null만 체크(최근버전부터 deprecated됨)
hasText -> "", null, whitespace 체크

0개의 댓글