JAVA

String null 빈값 체크

IT Lab 2020. 1. 13. 23:13

Java에서 String의 null & 빈값 체크시에 아래와 같이 사용하는 경우가 있는데,

 

String str = "";
if (str == null && "".equals(str)) {
	//str is empty
}

 

 

srping에서 제공해주는 StringUtils 를 이용하면 아래와 같이 짧고 이쁘게 처리 할 수 있습니다.

 

import org.springframework.util.StringUtils;

String str = "";
if (StringUtils.isEmpty(str)) {
	//str is empty
}