728x90
반응형
이 문서는 추후 다시 볼 목적으로 정리한 글입니다.
String 을 Split 해서 map 으로 만든다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String s = "a1=1,2,3/a2=4,5,6"; | |
Map<String, String> map = Pattern.compile("/") | |
.splitAsStream(s.trim()) | |
.map(i -> i.split("=", 2)) | |
.collect(Collectors.toMap(a -> a[0], a -> a[1])); | |
for (String key : map.keySet()) { | |
System.out.println(map.get(key)); | |
} | |
'Java > stream' 카테고리의 다른 글
java stream 예제 - list 안의 list 안의 map 에 대해서 filter 걸기 (0) | 2020.07.09 |
---|---|
java stream 예제 - String array --> map 으로 변환 (0) | 2020.07.09 |
java stream 예제 - set --> map, list --> map (0) | 2020.07.09 |
java stream 예제 - map 에서 최소,최대 값 구하기. (0) | 2020.07.09 |
java stream 예제 - map 의 value 을 기반으로 string array 로 변환 (0) | 2020.07.09 |
댓글