MCQs
obj.length() returns the length allotted to object obj at time of initialization and obj.size()
returns the size of current object obj, each BitSet element is given 16 bits therefore the
size is 4 * 16 = 64, whereas length is still 5.
Output:
$ javac Bitset.java
$ java Bitset
5 64
main() method must be declared static, main() method is called by Java’s run time system before
any object of any class exists.
trimTosize() is used to reduce the size of the array that underlines an ArrayList object.
An element in a LinkedList object can be changed by first using get() to obtain the index
or location of that object and the passing that location to method set() along with its new
value.
None.
An element in a LinkedList object can be changed by first using get() to obtain the index
or location of that object and the passing that location to method set() along with its new
value.
Maps revolve around two basic operations - get() and put(). to put a value into a map,
use put(), specifying the key and the value. To obtain a value, call get() , passing the
key as an argument. The value is returned,
obj.elementAt(1) returns the value stored at index 1, which is 2.
Output:
$ javac vector.java
$ java vector
2
Hashtable object obj contains values 3, 2, 8 when obj.contains(new Integer(5)) is executed
it searches for 5 in the hashtable since it is not present false is returned.
Output:
$ javac hashtable.java
$ java hashtable
false
None.
Output:
$ javac Bitset.java
$ java Bitset
{0, 1, 3, 4}