且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何向Map中的Set添加值?

更新时间:2023-12-06 14:04:16

如果我理解正确,不难。

Not difficult if I understand correctly.

Map<String, Set<Integer>> reqdMap = new HashMap<String, Set<Integer>>();

//Form the set corresponding to apple.
Set<Integer> appleSet = new HashSet<Integer>();
appleSet.add(1);
...


reqdMap.put("apple", appleSet);

//To Retrieve
appleSet = reqdMap.get("apple");