需要帮助用字符串映射构造字符串键的HashMap吗
我有项目列表(字符串)和相应的用户,我从用户那里获取这些用户作为输入: 项目1,用户1 项目1,用户2 项目1,用户3 项目2,用户4 项目2,用户5 我希望这些数据的格式如下: 项目1:用户1、用户2、用户3 项目2:用户4,用户5 我正在尝试在hashmap中加入相同的内容需要帮助用字符串映射构造字符串键的HashMap吗,hashmap,Hashmap,我有项目列表(字符串)和相应的用户,我从用户那里获取这些用户作为输入: 项目1,用户1 项目1,用户2 项目1,用户3 项目2,用户4 项目2,用户5 我希望这些数据的格式如下: 项目1:用户1、用户2、用户3 项目2:用户4,用户5 我正在尝试在hashmap中加入相同的内容 HashMap<String, HashSet> hsp = new HashMap<String, HashSet>(); HashSet<String> userHash =
HashMap<String, HashSet> hsp = new HashMap<String, HashSet>();
HashSet<String> userHash = new HashSet<String>();
HashMap hsp=newhashmap();
HashSet userHash=新HashSet();
有人能帮我理解怎么做吗?我接受用户提供的项目名称和用户名。如下初始化HashMap和HashSet
HashSet<String> hashset=new HashSet<String>();
HashSet<String> hashset2=new HashSet<String>();
HashMap<String, HashSet> hashmap=new HashMap<String, HashSet>();
Hash map is {project2=[User4, User5], project1=[User3, User2, User1]}
最后将HashSet添加到HashMap
hashmap.put("project1", hashset);
hashmap.put("project2", hashset2);
因此,您需要的o/p如下
HashSet<String> hashset=new HashSet<String>();
HashSet<String> hashset2=new HashSet<String>();
HashMap<String, HashSet> hashmap=new HashMap<String, HashSet>();
Hash map is {project2=[User4, User5], project1=[User3, User2, User1]}