I have a GUI application which lets user to create sections and subsections for a specific section. The user can add new sections and add new subsections to a section any time. Finally I have a list viewer which will display the whole things every time I click a 'Refresh' button.
For the section part, I have created a List of string:
public static ArrayList<String> sections = new ArrayList<String>();
For the subsection part I want to create a List of List which will create a List of all the sections. I have used something like this, but the problem is I cannot uniquely identify each List using a section name:
public static ArrayList<ArrayList<String>> subsections = new ArrayList<ArrayList<String>>();
I want a data structure which will let me create a list based on a section name and will also let me add string in it any time. Any help?
你需要Map
,因为它是一个键值对的集合。
public static Map<String,List<String>> subsections = new HashMap<String,List<String>>();
使用HashMap
Map<String, List<String>> section = new HashMap<String, List<String>>();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.