Suneel Suneel - 7 months ago 20
Java Question

how to remove nested entry in a nested map using dot notation

I have a nested map, something like this:


Is there a way to remove the city entry using a key like ""? So I am looking for something like

Answer Source

Not natively, no, though you could write yourself a method to parse your extended map key using String.split("\\."), like this:

public void nestedRemove(Map map, String keyToRemove)
    String string = "";
    String[] keys = string.split("\\.");
    Map subMap = null;
    for(int i = 0; i < keys.length -1; i++)
        subMap = subMap.get(keys[i]);