[Java] - 자바 String null 체크

[Java] - 자바 String null 체크

반응형

#자바 null 체크 메소드

#param: str String

#return: null이면 "", 아니면 str

public class test { public static String checkNull(String str) { return (str == null || str.equals("")) ? "" : str; } public static void main(String[] args) { System.out.println(checkNull("hello")); // hello System.out.println(checkNull("")); // "" } }

728x90

반응형

from http://pingfanzhilu.tistory.com/309 by ccl(A) rewrite - 2021-09-28 11:01:14