title: Is there a simple way to create a hierarchical data structure in Java that can be modified at runtime and saved to a file? (Android Studio)
body: <p>I'm trying to find a simple way in Java/Android Studio to create a runtime-modifiable data structure that I can save/load from file that will be parsed to create a hierarchy of buttons (buttons that lead to child buttons).  In javascript I could do something like this:</p>
  
  <pre><code>var categories = new Object(
      "Entertainment": new Object(
          "Movie": null),
      "Exercise": new Object(
          "Upper Body": null,
          "Lower Body": new Object(
              "Squats": null
          ),
          "Dance": null)
  );
  </code></pre>
  
  <p>and then I could modify this object at runtime, use the data-structure to update and create a hierarchy of buttons, then serialize it to JSON and save it to a file to reload any edits the user made.</p>
  
  <p>To accomplish this I tried to create a tree/node data structure but I'm getting errors that I don't understand:</p>
  
  <pre><code>public static class Branch extends HashMap{
          public HashMap&lt;String, HashMap&gt; Branch(String str, HashMap node){
              HashMap&lt;String, HashMap&gt; hmap = new HashMap&lt;&gt;();
              hmap.put(str, node);
              return hmap;
          }
      }
  
      public static class ButtonHierarchy {
          private ArrayList&lt;HashMap&gt; categories;
  
          public ButtonHierarchy(){
              ArrayList&lt;HashMap&lt;String, HashMap&gt;&gt; categories = new ArrayList&lt;&gt;();
  
              categories.add(new Branch("entertainment", new HashMap()));
              categories.add(new Branch("exercise", null));
  
          }
  
          public Iterator&lt;Map.Entry&gt; iterator() {
              return categories.iterator();
          }
      }
  </code></pre>
  
  <p>Android Studio flags the <code>categories.add</code> calls because <code>Branch() in Branch cannot be applied to:
  (java.lang.String, java.util.HashMap)</code>
  I don't understand because I defined the <code>Branch</code> constructor to accept those types.</p>
  
  <p>Maybe I'm going about this in a way that doesn't lend itself to Java?  Is there already a standard Java class/lib that simplifies making this kind of mechanism?  I'm open to a totally different approach if it will simplify things!!  I'm not concerned about speed/memory because the button hierarchy will not be very big.</p>
  
  <p>Thanks in advance</p>