ArrayList Size Method
Consider the following code segment. Which statement, when used to replace // Missing Code, will correctly store the number of elements in the ArrayList in the size variable?
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("Alpha");
list.add("Beta");
// Missing Code
System.out.println("Size: " + size);
}
}
A
int size = list.getSize();
B
int size = list.size();
C
int size = list.length;
D
int size = list.size;
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | geethasailaja | 2 | 2 | 0m 35s | 165 |
| #2 | kaisuki | 1 | 2 | 0m 00s | 90 |
| #3 | bommasam000 | 1 | 1 | 0m 12s | 88 |
| #4 | singhris000 | 1 | 1 | 0m 12s | 88 |
| #5 | y.seong2027 | 1 | 2 | 34m 02s | -1,952 |
Items per page:
10
1 – 5 of 5
APFIVE