Exam
Name___________________________________
 
TRUE/FALSE.  Write 'T' if the statement is true and 'F' if the statement is false. 
1) 

Arrays have a built in toString method that returns all of the elements in the array as one String with "\n" inserted between each element. 

1) 

_______ 

 
2) 

Java arrays can store primitive types and Strings, but cannot store any other type of Object other than Strings. 

2) 

_______ 

 
3) 

A Java main method uses the parameter (String[ ] variable) so that a user can run the program and supply "command-line" parameters. Since the parameter is a String array, however, the user does not have to supply any parameters. 

3) 

_______ 

 
4) 

An array index cannot be a double, boolean or String. 

4) 

_______ 

 
5) 

If the following statement is performed: CD[ ] mycollection = new CD[200]; where CD is a previously defined class, then mycollection[5] is a CD object. 

5) 

_______ 

 
6) 

It is possible to sort an array of int, double or String, but not an array of any other class, such as a CD class. 

6) 

_______ 

 
7) 

To swap the 3rd and 4th elements in the int array values, you would do:
	values[3] = values[4];
	values[4] = values[3]; 

7) 

_______ 

 
8) 

In Java, an array can only store one type of data. For instance, you cannot create an array that stores both double and String values. 

8) 

_______ 

 
9) 

In a two-dimensional array, both dimensions must have the same number of elements, as in [10][10]. 

9) 

_______ 

 
10) 

The statement int[ ] list = {5, 10, 15, 20}; initializes list to have 4 int values. 

10) 

______ 

 
11) 

An array, when instantiated, is fixed in size, but an ArrayList can dynamically change in size when new elements are added to it. 

11) 

______ 

 
12) 

If a and b are both int arrays, then a = b; will copy all elements of b into a. 

12) 

______ 

 
13) 

Since a binary search is faster, there is no reason to use a linear search over a binary search. 

13) 

______ 

 
14) 

Each pass of a binary search eliminates approximately half the remaining elements from consideration. 

14) 

______ 

______ 

 
23) 

Unlike an array, an ArrayList object can grow and shrink in size. 

23) 

______ 

 
24) 

An ArrayList can store only objects, not primitive types. 

24) 

______ 

 
25) 

If a is an ArrayList, we can say a.add(5); to add an integer to a. 

25) 

______ 

 
26) 

Foreach loops can be used with ArrayList objects, but not with arrays. 

26) 

______ 

 
27) 

An ArrayList can store any type of object, but it is not possible to store objects of two different types in the same ArrayList. 

27) 

______ 

 
28) 

In order to store primitive values in an ArrayList, wrapper classes must be used. 

28) 

______ 

 
29) 

ArrayLists can store primitive types when the generics syntax is used, as in ArrayList<int>. 

29) 

______ 

FR
private int[] nums;

Create a method public void printUnder(int x)  that will print out all values less than x

Create a method public ArrayList<Integers> findDivBy5() that will return as an arraylist all values in the nums array that are evenly divisble by 5.

Private ArrayList<Strings> aList;

Create a method public void removeItems(char c) this will remove all items in alist that start with the letter c.  Use getChar(0) to find the first letter of the string.

Create a method public boolean containsName(String name) that will search through the array and return true if any name has jeff in it, or false otherwise

 
1) 

FALSE 

2) 

FALSE 

3) 

TRUE 

4) 

TRUE 

5) 

TRUE 

6) 

FALSE 

7) 

FALSE 

8) 

TRUE 

9) 

FALSE 

10) 

TRUE 

11) 

TRUE 

12) 

FALSE 

13) 

FALSE 

14) 

TRUE 

15) 

FALSE 

16) 

FALSE 

17) 

TRUE 

18) 

FALSE 

19) 

TRUE 

20) 

TRUE 

21) 

FALSE 

22) 

FALSE 

23) 

TRUE 

24) 

TRUE 

25) 

TRUE 

26) 

FALSE 

27) 

FALSE 

28) 

TRUE 

29) 

FALSE