多选题 What is the value of the size variable at the completion of this code segment?
ArrayList <Object> sampleArrayList = new ArrayList <Object>();
sampleArrayList.add(new Object());
sampleArrayList.ensureCapacity(15);
sampleArrayList.add(new Object());
int size = sampleArrayList.size();
  • A. 0
  • B. 1
  • C. 2
  • D. 10
  • E. 15
  • F. A compile time error will be generated.
  • G. A runtime exception will be thrown.
【正确答案】 C
【答案解析】ArrayList的长度基于其中对象的数目,而不是其容量。A、B、D、E、F和G不正确,因为ArrayList的长度基于其中对象的数目,而不是其容量。