Preview

16 - Introduction to ArrayList

 1. Java has a class called ArrayList which is a ___________ array. An ArrayList has an underlying array that grows or shrinks as needed.

  deletable

  re-sizable

  executable

  mini

 2. An ArrayList is __________ meaning it can change during runtime by adding and removing objects from it.

  mutable

  static

  a class

  immutable

 3. What will the following code print, when executed?
import java.util.*; // import everything at this level
public class Test
{
    public static void main(String[] args)
    {
       ArrayList nameList = null;
       System.out.println(nameList);
    }
 }

  It will print: 0

  null

  nameList

  Error

 4. What is the output of this code?
import java.util.*; // import everything at this level
public class Test
{
    public static void main(String[] args)
    {
       ArrayList nameList = new ArrayList();
       System.out.println("The size of nameList is: " + nameList.size());
       ArrayList list2 = null;
       System.out.println("The size of list2 is: " + list2.size());
    }
}

  The size of nameList is: error

  The size of nameList is: null

  The size of nameList is: list2

  The size of nameList is: 0

 5. ArrayLists can only hold primitive values, not objects.

  TRUE

  FALSE

 6. The following code shows the correct way to create an ArrayList of integers.
ArrayList[int] numbers = new ArrayList();

  TRUE

  FALSE

 7. The wrapper class Integer is used to hold integers in an ArrayList, as shown below.
ArrayList numbers = new ArrayList();

  TRUE

  FALSE

 8. When ArrayList is specified, the types of the reference parameters and return type when using its methods are type E.

  FALSE

  TRUE

 9. The ArrayList constructor ArrayList() constructs an empty list of size 0.

  FALSE

  TRUE

 10. ArrayList is generally NOT preferred over ArrayList because it doesn't allow the compiler to find errors that would otherwise be found at run-time.

  TRUE

  FALSE