BAEL-8901 Add section in "Stream operations on Strings" article
- Added string array to map example.
This commit is contained in:
@@ -2,6 +2,7 @@ package com.baeldung.string;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -32,5 +33,12 @@ public class JoinerSplitter {
|
||||
.mapToObj(item -> (char) item)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Map<String, String> arrayToMap(String[] arrayOfString) {
|
||||
return Arrays.asList(arrayOfString)
|
||||
.stream()
|
||||
.map(str -> str.split(":"))
|
||||
.collect(Collectors.<String[], String, String>toMap(str -> str[0], str -> str[1]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user