I am trying to create a content management system in Java, where I insert chapter names and create sections inside a chapter. I have used the following data structures:
static ArrayList<String> chapters = new ArrayList<String>();
static Map<String,ArrayList<String>> subsections = new HashMap<String,ArrayList<String>>();
Now, for insertion, I am using the following code:
ArrayList<String> secname = new ArrayList<String>();
secname.add(textField.getText());
MyClass.subsections.put("Chapter", secname);
The problem is I am getting the last element, the rest of the elements are getting overwritten. But, I cannot use a fixed ArrayList for the chapters. I have to insert strings runtime and from the GUI. How do I overcome this problem?
Chapterfor all the keys?