Fastest way to get all values from a Map where the key starts with a certain expression

前端 未结 5 2000
不思量自难忘°
不思量自难忘° 2020-12-15 05:58

Consider you have a map myMap.

Given the expression \"some.string.*\", I have to retrieve all the values from m

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 06:42

    Remove all keys which does not start with your desired prefix:

    yourMap.keySet().removeIf(key -> !key.startsWith(keyPrefix));
    

提交回复
热议问题