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.

  executable

  re-sizable

  deletable

  mini

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

  immutable

  a class

  static

  mutable

 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);
    }
 }

  Error

  null

  It will print: 0

  nameList

 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: list2

  The size of nameList is: 0

  The size of nameList is: error

  The size of nameList is: null

 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();

  FALSE

  TRUE

 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.

  TRUE

  FALSE

 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