gpt4 book ai didi

java - 获取indextOutOfBoundException

转载 作者:行者123 更新时间:2023-12-01 11:35:51 24 4
gpt4 key购买 nike

Ifdsfafadsfasd 几个 fv afwqf adsfdfadfsafdsafewfdsfsdfdsfsfwefds safsda {fdsfasd

     int foundIndex = Collections.binarySearch(keys, key, 

return foundIndex;
}


public int compareTo(K otherKey)
{
int result = 0;
for(int i = 0; i < keys.size(); i++)
{
result = ((Comparable<K>) keys.get(i)).compareTo(otherKey);
}
return result;
}
}

失败的测试用例:

@Test(timeout=1000) public void faals_order1(){
IMiniMap<String,Integer> map = new<String,Integer>();

assertEquals(al("Luigi","Mario","Peach","Toad"),map.keys());
assertEquals(al(2,1,3,4), map.values());
}

最佳答案

您需要检查 indexOf 返回的值以确保找到该值。如果值不存在,indexOf 将返回 -1

关于java - 获取indextOutOfBoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30005007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com