我目前有一个数组列表名列表,其中包含大量的数字(双打)。我需要这个大阵列表分成8倍,且通过我这样做:搜索数组列表
//Array List "list" contains close to 8 million numbers in it
for (int c1 = 0; c1 < list.size(); c1++)
{ //for
counter1++;
if (counter1 % rows ==1)
ID.add(list.get(c1));
else if (counter1 % rows ==2)
Contract.add(list.get(c1));
else if (counter1 % rows == 3)
Date.add(list.get(c1));
else if (counter1 % rows == 4)
Open.add(list.get(c1));
else if (counter1 % rows == 5)
High.add(list.get(c1));
else if (counter1 % rows == 6)
Low.add(list.get(c1));
else if (counter1 % rows == 7)
Close.add(list.get(c1));
else if (counter1 % rows == 8)
Volume.add(list.get(c1));
} //for
每8个号是重要信息的新行的开始。
例如。 ID合同日期开仓高低关闭体积 ID1合同1日期1打开1高1低1关闭1容量1
之前我问是否有更好的方法来组织这一点。我现在有一个不同的问题。有没有一种方法可以在使用for循环之外搜索数组列表?我可以提示用户输入一个ID和Contract,然后让我的程序以比使用for循环更高效的方式在代码中搜索它,而不是象我一样组织数组列表?
您可以使用HashMap,您使用该id作为键。 – Jakob
你有没有想过使用HashMap http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html –
使用数据库,可能在内存中。 – kan