b.
c.
d.
e.
154.
peek(): This returns the last added object in the queue.
poll(): This returns the last added object in the queue and
removed it from the queue.
remove(Object O): This removes the object from the queue.
add(E e): This adds an object to the queue.
This method
throws an Exception if it is not possible to add the object to
the queue.
Is it possible to mix generic and non–generic collections?
If so, give example.
Answer:
Yes, it is possible to mix generic and non–generic collections.The
following code snippet demonstrates this:
public void insertDouble() {
List
myDoubleList = new ArrayList();
myDoubleList.add(2.0); // Line 1
myDoubleList.add(4.0); // Line 2
insertSomethingElse(myDoubleList);
}
public void insertSomethingElse(List myDoubleList)
{//Line 3
myDoubleList.add(“Hello World”); //Line 4
}
In the above code, Line 1 and Line 2 add double literals to the list
which is a List with generic Double specified. The code then
invoked the insertSomethingElse() method with this double
List. In the method declaration at Line 3, the generic type is not
specified for the myDoubleList variable. So, any type of value
can be added to this List. Line 4 adds a string literal into the List.