Java TreeMap.putAll发出的钥匙超出范围
在我的代码中Java TreeMap.putAll发出的钥匙超出范围,java,Java,在我的代码中 SortedMap<Integer, Data> subMap; subMap = (db.getDataMap()).tailMap(previousServer); SortedMap<Integer, Data> temp = (db.getDataMap()).headMap(presentServer); //System.out.println(
SortedMap<Integer, Data> subMap;
subMap = (db.getDataMap()).tailMap(previousServer);
SortedMap<Integer, Data> temp = (db.getDataMap()).headMap(presentServer);
//System.out.println(subMap);
//System.out.println(temp);
subMap.putAll(temp);
SortedMap子映射;
subMap=(db.getDataMap()).tailMap(previousServer);
SortedMap temp=(db.getDataMap()).headMap(presentServer);
//系统输出打印LN(subMap);
//系统输出打印项次(温度);
子贴图putAll(温度);
假设tailMap()不返回任何内容,所以subMap是一个空映射,但temp几乎没有键值对。
因此,通过subMap.putAll(temp)将temp添加到subMap会给我“密钥超出范围”。
但是,如果我做临时putAll(subMap),那么一切都很好
原因可能是什么?请参见
注意:有几种方法返回键范围受限的子贴图。这些范围是半开放的,也就是说,它们包括其低端,但不包括其高端(如适用)。如果您需要一个闭合范围(包括两个端点),并且密钥类型允许计算给定密钥的后续项,只需请求从lowEndpoint到后续项(highEndpoint)的子范围。例如,假设m是一个键为字符串的映射。下面的习惯用法获得一个视图,其中包含m中键介于low和high之间的所有键值映射,包括:
SortedMap<String, V> sub = m.subMap(low, high+"\0");
SortedMap sub=m.subMap(低、高+“\0”);
类似的技术可用于生成开放范围(其中既不包含端点也不包含端点)。下面的习惯用法获得了一个视图,其中包含m中的所有键值映射,其键值介于低和高之间,并且是独占的:
SortedMap<String, V> sub = m.subMap(low+"\0", high);
SortedMap sub=m.subMap(低+“\0”,高);
从
IllegalArgumentException if fromKey is greater than toKey; or if this map itself has a restricted range, and fromKey or toKey lies outside the bounds of the range