티스토리 뷰
728x90
java의 컬렉션인 List에 관한 예제에서 기본값을 넣어줄 때
List<Integer> integerList = List.of(1, 2, 3, 4, 5);
List<Integer> integerList2 = Arrays.asList(1, 2, 3, 4, 5);
of() 정적 메서드는 자바 9부터 추가된 메서드이다.
어쨌든 List 값을 넣어주는 것은 동일한 것 같은데 무슨 차이일까 궁금해서 검색해봄.
Arrays.asList returns a mutable list while the list returned by List.of is immutable:
asList는 불변객체가 아니고 of는 불변객체로 만들어준다.
크게 뭔가 와닿는건 없는데 stackoverflow를 첨부 나중에 더 깨닫게되면 다시 씀.
stackoverflow.com/questions/46579074/what-is-the-difference-between-list-of-and-arrays-aslist
728x90
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- maven
- window
- mybatis
- LocalDate
- elasticsearch
- localtime
- input
- LocalDateTime
- Java
- Bash tab
- Github Status
- docker
- svn
- springboot
- mybatis config
- 프로페셔널 스튜던트
- oracle
- intellij
- JavaScript
- Linux
- Spring Security
- 북리뷰
- config-location
- 베리 심플
- Mac
- 오라클
- rocky
- Spring
- jQuery
- Kotlin
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함