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
設置的HashMap的關鍵設定器
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);
}
會不會有永遠是你'Map'只有兩個鍵 - 值對?將所有值加在一起總是等於100.0(例如,30.0 + 70.0 = 100.0)? – creemama
@creemama,是的只有兩個關鍵值對總是總計爲100. – AKIWEB