This example will show how to filter a map by keys creating a submap in groovy. First initializing a map of months then calling map.submap()
returning months contained in the first quarter. A comparable example demonstrates how to get a subset of a map in java java, java 8 and guava.
Filter map by key
@Test
void filter_map_by_key() {
def MONTHS = [
1: "January",
2: "February",
3: "March",
4: "April",
5: "May",
6: "June",
7: "July",
8: "August",
9: "September",
10: "October",
11: "November",
12: "December",
]
assert [1: "January",
2: "February",
3: "March"] == MONTHS.subMap([1, 2, 3])
}