LinkedHashMap<String, Double> testMap = (LinkedHashMap<String, Double>) sortByValue(commands.get(commandWithMaxNegativeOffset).getDataUsageCriteria());
从上面看,testMap
将包含类似{New=30.0, Previous=70.0}
值升序排列的东西,所以我想要做的是 if/else 循环中的下面的东西,因为目前我现在已经硬编码只是为了更有意义,但我想使用 testMap 而不是硬编码. key
如果条件匹配,我想设置为值by using key/value pair from map
double percent = r.nextDouble()*100;
if(percent > 1.0 && percent < 70.0(how can I use 70 from testMap instead of hardcoding)) {
//what to put below in place of Previous
commands.get(commandWithMaxNegativeOffset).setDataCriteria(Use the Key of 70.0 i.e Previous);
} else if(percent > 71 && percent < 100){
commands.get(commandWithMaxNegativeOffset).setDataCriteria(Use the Key of 30.0 i.e New);
}