Map
List
List1. Add (1 l);
List1. Add (2 l);
List
List2. Add (2 l);
List2. Add (3 l);
List
List3. Add (3 l);
List3. Add (4 l);
List
List4. Add (5 l);
List4. Add (6 l);
List
List5. Add (6 l);
List5. Add (7 l);
The map. The put (1 l, list1);
The map. The put (2 l, list2);
The map. The put (3 l, list3);
The map. The put (4 l, list4);
The map. The put (5 l, list5);
Map
- List
List
List
Map. ForEach ((key, value) - & gt; {
System. The out. Println (" outer key: "+ key);
List
Map. ForEach ((key1, value1) - & gt; {
System. The out. Println (" inner key: "+ key1);
if(! Collections. Disjoint (value, value1) & amp; & ! The key. The equals (key1)) {
System. The out. Println (" key: "+ key +" : "+ key1);
System. The out. Println (" value: "+ value +" : "+ value1);
KeyList. Add (key);
KeyList. Add (key1);
ValueList. AddAll (value);
ValueList. AddAll (value1);
/* else {}
System. The out. Println (" not join key: "+ key +" : "+ key1);
System. The out. Println (" not join value: "+ value +" : "+ value1);
} */
});
});
System. Out. Println (" keyList: "+ Arrays. ToString (keyList. The stream (). The distinct (). The toArray ()));
System. Out. Println (" valueList: "+ Arrays. ToString (valueList. The stream (). The distinct (). The toArray ()));
}
Example: list1 list2, list3 contain repeating elements, key in map2 - & gt; List put the map in list1 list2, list3 corresponding key collection of [1, 2, 3], the value - & gt; List put list1, list2, list3 to weight list [1, 2, 3, 4],
Expect results map2: key: value: [1, 2, 3] [1, 2, 3, 4]. Key: [4, 5] value: [5, 6]