메뉴136 [JAVA] Java의 String Empty 와 Blank 체크하기 Java의 String Empty 와 Blank 체크하기에 대해 알아봅니다. Empty와 Blank의 차이 Sring Empty : null 이거나 length(길이)가 없는 String String Blank : 공백으로만 되어있는 String Empty String Java6 이상부터는 String 클래스의 isEmpty 메소드로 체크하면 됩니다. String test = " "; if (test.isEmpty()) { log.info("isEmpty"); } else { log.info("isNotEmpty"); } //결과는 isNotEmpty 가 출력됩니다. test라는 String이 null이 들어올 수 있기 때문에 조건을 추가해준다면 다음과 같이 empty 를 체크하면 됩니다. String .. 2022. 3. 18. [JAVA] Java의 ArrayList를 변경불가능(Immutable)로 생성하는 방법 Java의 ArrayList를 변경불가능(Immutable)로 생성하는 방법에 대해 알아봅니다. ArrayList를 변경불가능하게 만들기 위해서는 JDK에서 지원하는 방법, Guava 라이브러리를 이용하는 방법 그리고 Apache Commons Collections 라이브러리를 이용하는 방법 세가지가 있습니다. JDK에서 지원 1) Collections 클래스를 이용하는 방법 Collections.unmodifiableList(list); 2) Java9 Java9에서는 List.of 인 static factory method를 이용해서 리스트를 생성하면 됩니다. ArrayList list = List.of("a","b","c"); Guava 라이브러리 ImmutableList.copyOf(list); .. 2022. 3. 17. [Tistory] 티스토리 구글 애드센스 신청방법 - 2022년 최신, 초보자 가이드 쉽게 따라하기 티스토리에 구글 애드센스를 신청하는 방법을 소개해 보겠습니다. 1. 시작하기 티스토리 1. 설정 > 수익 > Google AdSense 연동하기 클릭 2. 구글 로그인 구글 애드센스에 회원가입이 되어있지 않을경우, 오류 알림창이 뜨고, 새창으로 구글 애드센스 사이트 등록창이 열립니다. 구글 애드센스 티스토리 설정 > 수익 > Google AdSense 연동하기 클릭 연동후 Google AdSense 검토요청 클릭 확인 2022. 3. 17. [SpringSecurity] SpringSecurity에서 user detail 정보를 획득하기 이번에는 SpringSecurity에서 인증된 user detail 정보를 얻어오는 방법에 대해 알아봅니다. Bean 안에서 인증된 User 획득하기 SecurityContextHolder의 context에서 인증된 정보에서의 User의 name을 획득하기 Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String currentPrincipalName = authentication.getName(); 혹은 아래처럼 인증된 타입에 따른 분기를 추가하는게 더 좋을수도 있겠죠? Authentication authentication = SecurityContextHolder.getContext().ge.. 2022. 3. 17. 이전 1 ··· 28 29 30 31 32 33 34 다음