我有以下的TreeMap
:
TreeMap<Long,String> gasType = new TreeMap<>(); // Long, "Integer-Double"
gasType.put(1L, "7-1.50");
gasType.put(2L, "7-1.50");
gasType.put(3L, "7-3.00");
gasType.put(4L, "8-5.00");
gasType.put(5L, "8-7.00");
Map<Integer,TreeSet<Long>> capacities = new TreeMap<>);
关键字的格式为
1L
(一个Long
),值的格式为"7-1.50"
(由int
和double
连接而成,用-
分隔)。我需要创建一个新的
TreeMap
,其中关键字是通过获取原始Map
的值的int
部分获得的(例如,对于值"7-1.50"
,新关键字将为7
)。新Map
的值将是包含所有匹配新关键字的原始Map
的关键字的TreeSet
。因此,对于上述输入,
7
键的值将为Set
{1L、2L、3L}。我可以不使用
Stream
来完成这个操作,但我想使用Stream
来实现。非常感谢您的帮助。谢谢。