Csci 1302 Final Demo

10 Questions

Settings
CSCI Exam Quizzes & Trivia

Questions and Answers
  • 1. 
    The E get(int index) method of the List interface should throw an exception if. 
    • A. 

      The index passed to it is negative

    • B. 

      The index passed to it non negative

    • C. 

      The index passed to it is negative or greater or equal to the size of the list

    • D. 

      The index passed to is negative or greater than the size of the list

  • 2. 
    The difference between an array and an ArrayList is
    • A. 

      an ArrayList uses a LinkedList to hold its elements, an array does not.

    • B. 

      An array keeps track of its length while an ArrayList does not track comparable information

    • C. 

      C. arrays have a fixed size and cannot grow to accommodate more elements

    • D. 

      D. All of these

  • 3. 
    The position of an item within a list is called its 
    • A. 

      A. index

    • B. 

      B. rank

    • C. 

      C. level

    • D. 

      D. number

  • 4. 
    A constructor for an array-based list takes an integer parameter, to be used as the capacity of the internal array of the list. Which exception should the constructor throw if its parameter is zero or negative?
    • A. 

      IllegalArgumentException

    • B. 

      IllegalStateException

    • C. 

      NullPointerException

    • D. 

      RuntimeException

  • 5. 
    The size of an array-based list such as ArrayList
    • A. 

      Is the number of bytes of memory that the list can hold

    • B. 

      Is the number of elements that are currently stored in the list

    • C. 

      Is the length of its internal array

    • D. 

      None of these

  • 6. 
    The capacity of an array-based list such as ArrayList
    • A. 

      Is the number of bytes of memory that the list can hold

    • B. 

      is the number of elements that are currently stored in the list

    • C. 

      is the size of its internal array

    • D. 

      None of these

  • 7. 
     An ArrayList is so called because
    • A. 

      You can use array subscript notation to work with the ArrayList

    • B. 

      it is implemented as a class that uses an internal array to hold the elements of the list

    • C. 

      You can pass it as a parameter to any method that expects an array

    • D. 

      All of these

  • 8. 
    A new element is added to an ArrayList object at index k. Assuming the list has size s and does not have to be resized,
    • A. 

      The elements at current positions 0..k must be moved toward the beginning of the list

    • B. 

      the elements at current positions k..s-1 must be moved toward the end of the array

    • C. 

      C. the elements at current positions k..s must be moved toward the end of the array

    • D. 

      the element at position k is overwritten

  • 9. 
    The boolean contains(E element) method searches a ArrayList for a given element. A correct and efficient implementation of this method
    • A. 

      Throws an exception if the element is not found in the list

    • B. 

      Uses binary search to locate the element

    • C. 

      Uses sequential search to locate the element

    • D. 

      Returns 0 if the element is not found in the list

  • 10. 
    If a new element is added to an ArrayList whose internal array if already full,
    • A. 

      The add method throws an exception

    • B. 

      A new, bigger internal array is created, the elements are moved to the new array, the old internal array is deleted, and then the new element is added

    • C. 

      The new element is not added, and -1 is returned

    • D. 

      The new element is not added, and null is returned