让我们假设我们得到了以下两个数组
String[] keys = new String[] {"a", "b", "c", "aa", "d", "b"}
int[] values = new int[] { 1 , 2 , 3 , 4 , 5 , 6 }
Run Code Online (Sandbox Code Playgroud)
通过将这两个数组合并到HashTable中,我们得到以下结果
// pseudo-code
Map<String, Integer> dictionary = new HashTable<>(
("a" => 1)
("b" => 8) // because "b" appeared in index 1 and 5
("c" => 3)
("aa" => 4)
("d" => 5)
);
Run Code Online (Sandbox Code Playgroud)
我们怎么能用java Lambda样式做到这一点?
到目前为止,我有以下内容:
// this loops through the range given (used for index start and end) …Run Code Online (Sandbox Code Playgroud)