您没有开设可容纳您的物品和过道信息的课程吗?就像是:
public class Item { private String name; private int aisle; // constructor + getters + setters }如果不这样做,请考虑创建一个-
与尝试将这些属性粘贴到另一个ArrayList中的ArrayList中相比,这绝对是一种更好的方法。讲完类后,您将需要为对象编写比较器,或者使“
Item”
本身可比较:
public class Item implements Comparable<Item> { .. same stuff as above... public int compareTo(Item other) { return this.getAisle() - other.getAisle(); }}然后,您要做的就是调用sort:
List<Item> items = new ArrayList<Item>();... populate the list ...Collections.sort(items);



