map()

데이터의 변환

map()은 주로 Stream이나 Optional 인터페이스에서 사용된다. 스트림 내부의 요소를 차례대로 다른 형태로 변환하는 역할을 한다.

<R> Stream<R> map(Function<? super T, ? extends R> mapper);
  • 입력타입 T를 받아서 결과타입 R을 반환하는 Function 인터페이스를 인자로 받는다.
  • 요소의 개수는 유지하되, 그 내용물(타입이나 값)이 바뀐다.
  • 지연 연산, 중간 연산이므로 collect() 같은 최종 연산이 호출되기 전까지는 실제로 실행되지 않는다.

Map (Java Platform SE 8 )

 

Map (Java Platform SE 8 )

If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null. If the function returns null no mapping is recorded. If the function

docs.oracle.com

 

'Java' 카테고리의 다른 글

깔끔한 Service 코드 만들기(from, map, collect)  (0) 2026.01.26
from()  (0) 2026.01.26
collect()  (0) 2026.01.26
Java의 < > 기호 - 제네릭(Generics)  (0) 2026.01.26