我正尝试在Java中创建一个内容管理系统,我在其中插入章节名称并在章节内创建节。我已经使用了以下数据结构:现在在HashMap中StringList的ArrayList中添加动态内容
static ArrayList<String> chapters = new ArrayList<String>();
static Map<String,ArrayList<String>> subsections = new HashMap<String,ArrayList<String>>();
,插入,我使用下面的代码:
ArrayList<String> secname = new ArrayList<String>();
secname.add(textField.getText());
MyClass.subsections.put("Chapter", secname);
的问题是我得到的最后一个元素,该元素的其余部分是被覆盖。但是,我不能在章节中使用固定的ArrayList。我必须从GUI中插入字符串运行时。我如何克服这个问题?
你对所有的键使用'Chapter'? – 2013-02-17 16:09:45