152.
153.
a.
Answer:
The Queue interface is part of the Collection API and extends the
java.util.Collection interface. In addition
to Collection operations,
Queue provide features of a queue data structure like FIFO (First
in First Out). The Queue interface has several methods that allow
queue operations:
peek(): allows inspecting the element
at the top of the queue
poll(): removes the element at the top of the queue
offer(): insert an element into the queue
Explain the Comparator interface.
Answer:
Comparator is an interface that can be used for sorting. It has
been designated as a functional interface since Java 8. It has a
single abstract method called compare.
The compare method
accepts two objects and returns a boolean value that is the result
of comparison. Comparator can also be used to sort custom
object. For this, the corresponding
class needs to implement the
Comparator interface and provide an implementation for the
compare method. If you are using Java
8
or a higher version, you can also implement a Comparator
using a lambda expression.
Do'stlaringiz bilan baham: