본문으로 건너뛰기
김신건의 로그

[Spring] LinkedCaseInsensitiveMap

· 수정 · 📖 약 1분 · 203자/단어 #spring #util #map #case-insensitive #http
LinkedCaseInsensitiveMap, org.springframework.util.LinkedCaseInsensitiveMap, case insensitive map

정의

org.springframework.util.LinkedCaseInsensitiveMap<V>LinkedHashMap 을 기반으로 key 비교를 대소문자 무시 로 하는 Map. 단, 원본 key (대소문자 보존) 도 유지.

HTTP 헤더 같은 도메인에서 "Content-Type""content-type" 을 같은 key 로 다뤄야 할 때 핵심. Spring 의 HttpHeaders 등에서 내부적으로 사용.

사용

import org.springframework.util.LinkedCaseInsensitiveMap;

Map<String, String> m = new LinkedCaseInsensitiveMap<>();
m.put("Content-Type", "application/json");
m.put("Accept", "text/html");

m.get("content-type");       // "application/json"
m.get("CONTENT-TYPE");       // "application/json"
m.containsKey("accept");     // true

m.keySet();                  // ["Content-Type", "Accept"]   ← 대소문자 보존

내부 구조

LinkedHashMap<String, V> 을 백킹으로 사용하면서, 별도 caseInsensitiveKeys 맵에 lower-case key → original key 매핑 유지.

private LinkedHashMap<String, V> targetMap;
private Map<String, String> caseInsensitiveKeys;   // lower → original

어디서 만나는가

클래스용도
HttpHeadersHTTP 헤더 이름 case-insensitive
Servlet 의 헤더 wrapper일부 구현
설정 property 로딩 (일부 환경)

직접 만들 일은 드물지만, Spring API 가 반환하는 경우가 있어 동작을 알고 있어야 한다.

thread-safe 가 아니다

LinkedHashMap 처럼 단일 스레드 전용.

참고

💬 댓글

사이트 검색 / 명령어

검색

스크롤 = 확대/축소 · 드래그 = 이동 · 0 = 원래 크기 · ESC = 닫기