Array

  • Construct an array of Object and traverse it
class Student {
    public int id;

    public Student(int id) {
        this.id = id;
    }
}

// In another Class
Student[] students = new Students[nums];

for (int i = 0; i < nums; i++) {
    students[i] = new Student(i);
}
  • Construct a List of List eg.1: List> list = ArrayList>(); list.add(new ArrayList());

The reason is that generics are not covariant.

Consider simpler case:

    List<Integer> integers = new ArrayList<Integer>();
    List<Number> numbers = integers; // cannot do this
    numbers.add(new Float(1337.44));

Now List holds a Float, which is certainly bad.

Same for your case.

    List<ArrayList<Integer>> al = new ArrayList<ArrayList<Integer>>();
    List<List<Integer>> ll = al; // cannot do this
    ll.add(new LinkedList<Integer>())

Now you have a list ll which holds LinkedList, but the al is declared as a List of ArrayLists.

  • array缩小从小到大,array变大从大到小
  • array缩小的过程可以不用多一个循环,直接比较存进array,用一个值记录

  • array循环:寻找边界条件和index和array长度的对应关系。最好都换成从零开始(119)