Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java从映射中获取前置键_Java_Iterator_Treemap - Fatal编程技术网

使用java从映射中获取前置键

使用java从映射中获取前置键,java,iterator,treemap,Java,Iterator,Treemap,我这里有张地图 TreeMap<Integer, Float> matrixMap = new TreeMap<Integer, Float>(); 现在,我要获取一个键25的值。理想情况下,25在结果中不可用。我想得到24和36的值 duration = 25 我可以得到36的值,但是如何得到36的前导值呢 for(Map.Entry<Integer, Float> entry : matrixMap.entrySet()) { if(

我这里有张地图

    TreeMap<Integer, Float> matrixMap = new TreeMap<Integer, Float>();
现在,我要获取一个键25的值。理想情况下,25在结果中不可用。我想得到24和36的值

duration  = 25
我可以得到36的值,但是如何得到36的前导值呢

for(Map.Entry<Integer, Float> entry : matrixMap.entrySet()) {
    if(duration  < entry.getKey())
    {
        max = entry.getValue();
        break;
    }

}
for(Map.Entry:matrixMap.entrySet()){
if(持续时间
如何获得直接前置值(本例中为24键)


获取第一个键>=25的值的任何想法:

matrixMap.tailMap(25).values().next()
或:


要获得第一个键的值,我使用以下方法求解

int above = matrixMap.ceilingKey(duration);
int below = matrixMap.floorKey(duration);
logger.info("above="+above+", below="+below);
min = insuranceMatrixMap.get(below);
max = insuranceMatrixMap.get(above);
matrixMap.get(matrixMap.tailMap(25).firstKey())
matrixMap.get(matrixMap.headMap(25).lastKey())
int above = matrixMap.ceilingKey(duration);
int below = matrixMap.floorKey(duration);
logger.info("above="+above+", below="+below);
min = insuranceMatrixMap.get(below);
max = insuranceMatrixMap.get(above);