MCQs
Arrays in java are implemented as objects, they contain an attribute that is length which
contains the number of elements that can be stored in the array. Hence a1.length gives
10 and a2.length gives 5.
output:
$ javac Output.java
$ java Output
10 5
trimTosize() is used to reduce the size of the array that underlines an ArrayList object.
Output:
$ javac Output.java
$ java Output
2
TreeSet class uses set to store the values added by function add in ascending order
using tree for storage
Output:
$ javac Output.java
$ java Output
[1, 3, 4, 8, 9]
arr.length() is 5, so the loop is executed for three times.
output:
$ javac Output.java
$ java Output
1 2 3
Math.pow(x, y) methods returns value of y to the power x, i:e x ^ y, 2.0 ^ 3.0 = 8.0.
Output:
$ javac Output.java
$ java Output
8.0
obj.entrySet() method is used to obtain a set that contains the entries in the map.
This method provides set view of the invoking map.
Output:
$ javac Maps.java
$ java Maps
[A=1, B=2, C=3]