我注意做一些数组列表操作,但我遇到了一个问题,创建了一个无限循环。有人可以解释一下为什么吗?
ps 不要担心跟踪命令,我正在为 smartfoxserver 2x 实例创建自定义 java 扩展。
String deckOf4Array[] = new String[] {"AD","KD","QD","JD","10D","9D","8D","7D","6D","AH","KH","QH","JH","10H","9H","8H","7H","6H","AC","AS","KS"};
List<String> deckOf4List = new ArrayList<String>(Arrays.asList(deckOf4Array));
for(int n=0; n<4; n++)
{
int cardindex = new Random().nextInt(deckOf4List.size()-1);
trace("cardindex: " + cardindex);
for (ListIterator<String> iter = deckOf4List.listIterator(); iter.hasNext(); )
{
// Here goes infinite loop
trace("cardindex: " + cardindex);
if(cardindex == iter.nextIndex())
{
// Here goes manipulations
}
iter.remove();
}
}