To remove all the elements in the list in the following code, replace the underlined blank space with __________.

```
import java.util.*;

public class Test {
public static void main(String[] args) {
______________ list = new ArrayList<>();
list.add(0);
list.add(1);
list.add(2);

for (int i = 0; i < 3; i++) {
list.remove(i);
}
System.out.println(list);
}
}
```
a. Collection
b. List
c. ArrayList
d. AbstractList


a If list is declared as Collection, list.remove(i) is the same as list.remove(new Integer(i)). If list is declared as List, ArrayList, or AbstractList, list.remove(i) is to remove the element at the index i. The list has three elements and the last index is 2 . After removing the first element, the last index becomes 1 . After removing another element, the last index becomes 0 . You will receive an IndexOutOfBoundsException.

Computer Science & Information Technology

You might also like to view...

When defining an inner class to be a helper class for an outer class, the inner classes access should be marked as:

a. Public b. Private c. Protected d. Package access

Computer Science & Information Technology

Personal effects, moveable property and goods, such as cars, bank accounts, wages, securities, a small business, furniture, insurance policies, jewelry, patents, and pets are all examples of _________.

A. intellectual property B. real property C. personal property D. cyber property

Computer Science & Information Technology

What would the browser output if the following script is executed?

``` < SCRIPT LANGUAGE = "JavaScript" > var array = [ [ 1, 2, 3 ], [ 1, 2, 3 ] ]; for ( var i in array ) { for ( var j in array[ i ] ) document.write( array[ i ][ j ] + " " ); document.writeln("
"); } < /SCRIPT > ``` a) Nothing, the script would generate an error b) 1 2 3 c) 1 2 3 4 5 6 d) 1 2 3 1 2 3

Computer Science & Information Technology

What are the two main types of diagrams in U M L?

What will be an ideal response?

Computer Science & Information Technology