반응형

Object.toString() 꼴에서 Null에 대해서 NullPointerException에 대해서 일관된 처리를 하는 방법에 대해 찾아봤다.

 

 


 

 

정리 : String.valueOf(null)은 "null"을 반환하고, null.toString()은 NullPointerException을 throw한다.

반응형
반응형

자바 11에서 String 추가된 메서드 중 strip()과 기존에 있던 trim()이 뭐가 다른지 찾아봤다.

---

 

정리 )

- String::trim() : ' '만 제거

- String::strip() : whitespace 모두 제거 ( ex - \t )

반응형
반응형

배열에서의 특정 값 유무 확인 방법

 

1. Stream 사용

boolean contains = Arrays.stream(arr).anyMatch(String::equals);

 

2. Set 사용

  1. java9 이상 : Set.of().contains()
  2. java9 미만 : new HashSet<>(Arrays.asList(arr))

 

2021-11-06

3. ImmutableSet

ImmutableSet.of().contains()

반응형

+ Recent posts