I would try out TreeMap
from java.util. This is a map which does what u need. It manages the keys based on a natural order (defined by a comparator
in the key class). The methods tailMap
and headMap
gives you a map with keys you need.
Example
public static void main(String[] args) {
TreeMap<String, Object> map = new TreeMap<String, Object>();
map.put("com","1");
map.put("com.aa","2");
map.put("com.aa.bb","3");
System.out.println(map.get("com"));
System.out.println(map.tailMap("com").values()); // ["1","2","3"]
System.out.println(map.get("com.aa")); //return ["2","3"]
System.out.println(map.tailMap("com.aa").values());
}