본문 바로가기
Java/stream

java stream 예제 - String 을 Split 해서 map 으로 만든다.

by 무대포 개발자 2020. 7. 9.
728x90
반응형

이 문서는 추후 다시 볼 목적으로 정리한 글입니다.

String 을 Split 해서 map 으로 만든다.

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));
}

댓글