2
我有一个ArrayList
。该数组可以包含4个项目或4000个项目。我正在寻找中间4件物品。我的猜测是得到size/2
-2 +2。什么是最有效的方式来做到这一点,你如何处理奇数?如何获得Arraylist的中心4()
if (comparables.size() > 4) {
int size = comparableVehicles.size();
System.out.println("size " + size);
int middle = size/2;
System.out.println("middle " + middle);
int bottom = middle - 2;
System.out.println("bottom " + bottom);
this.comparables = comparables.subList(bottom, bottom + 4);
}
好,太好了,谢谢。 – 2014-12-08 07:47:46