Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

JAVA

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

Question What are the requirements for a safe harbor 401(k) plan?30

Answered: 1 week ago