Question: JAVA Which of the following statements about the ArrayList implementation below are TRUE? Choose TWO. 1 public class ArrayList { 2 private E[] data =

JAVA

JAVA Which of the following statements about the ArrayList implementation below are

TRUE? Choose TWO. 1 public class ArrayList { 2 private E[] data

Which of the following statements about the ArrayList implementation below are TRUE? Choose TWO. 1 public class ArrayList { 2 private E[] data = (E[])new Object[8]; 3 private int size; 4 public void add(int index, E e) { 5 if (index size) 6 throw new IndexOutOfBoundsException 7 ("Index: " + index + ", Size: " + size); 8 ensureCapacity(); 9 for (int i = size - 1; i >= index; i--) 10 data[i + 1] = data[i]; 11 data[index] = e; 12 size++; 13 } 14 private void ensureCapacity() { 15 if (size >= data.length) { 16 E[] newData = (E[])(new Object[(int) (size * 1.5)]); 17 System.arraycopy(data, o, newData, o, size); 18 data = newData; 19 20} Line 10 is always executed if Line 09 is executed. If the data array is fully occupied, adding an element will double the size of data array by 50% The shifting of elements in the add method starts from the beginning of the ArrayList. If the size of the ArrayList is 8, invoking add(8, e) won't throw an exception (assume e is valid). When implementing a Queue, we can use another data structure as the data field to hold the elements in the Queue. Which of the following statements about this implementation are TRUE? Choose TWO. This implementation is known as composition. LinkedList is a better data field than ArrayList. Enqueue method invokes the removeFirst method of the underlying data structure. Dequeue method invokes the addFirst method of the underlying data structure

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!