Collect(Collectors.toList()) ๋ฅผ toList()๋ก ํญ์ ๋์ฒดํด์ ์จ๋ ๋ ๊น?Stream.toList()๋ฐ์ํ ์ด์ ETC
Collect(Collectors.toList()) ๋ฅผ toList()๋ก ํญ์ ๋์ฒดํด์ ์จ๋ ๋ ๊น?
Stream.toList()
- JDK17 ๊ธฐ๋ฐ์์ ์คํธ๋ฆผ์ ์ฌ์ฉํ์ฌ
Collect(Collectors.toList())
์ ์ฌ์ฉํ๋ฉด ์ด์ toList()
๋ฅผ ์ฌ์ฉํ๋ผ๊ณ ๊ถํด์ฃผ๊ณ ์๋ค.

๋๋ ๊ฐ๋
์ฑ์ด ์ข์์ ๋ณํํด์ ์ฌ์ฉํ๋๋ฐ ์ํ๋ฆฌํฐ ๊ฐ์ ์์ ๋ฅผ ๋ณด๋ฉด์ ๊ณต๋ถํ๋ ์ค ์ด์ํ ์ํฉ์ด ๋ฐ์ํ๋ค.


๋ญ์ผ ์ด๊ฑฐ ์์ด๋โฆ
๋ฐ์ํ ์ด์
- collect(Collectors.toList()์ toList()๊ฐ ์์ ํ ๋๊ฐ์ ํํ์ ๊ตฌํ์ฒด๋ก ๋ฐํ๋์ง ์๋๋ค.
- collect(Collectors.toList()) ๋ ArrayList๋ฅผ ๋ฐํํ๋ค.
- There are no guarantees on the type, mutability, serializability, or thread-safety of the List returned
- toList()๋ Collectors.UnmodifiableList ๋๋ Collectors.UnmodifialbeRandomAccessList๋ฅผ ๋ฐํํ๋ค.
[๋ช
ํํ ์ฐจ์ด]
- ์ด๋ฆ์์ ๋ํ๋ ๊ฒ์ฒ๋ผ ์์ ์ด ๊ฐ๋ฅํ ๊ตฌํ์ฒด์ ์์ ์ด ๋ถ๊ฐ๋ฅํ ๊ตฌํ์ฒด์ ์ฐจ์ด์ ์ด ์กด์ฌํ๋ค.