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