Java Reference
In-Depth Information
Element >= 4 is 4
Element < 12 is 82
Element <= 12 is 82
Element > 12 is 11
Element >= 12 is 11
Thefirstfouroutputlinesbeginningwith Element pertaintoanascending-orderset
where the element being matched ( 4 ) is a member of the set. The second four Ele-
ment -prefixedlinespertaintoadescending-ordersetwheretheelementbeingmatched
( 12 ) is not a member.
Aswellaslettingyouconvenientlylocatesetelementsviaitsclosest-matchmethods
( ceiling() , floor() , higher() ,and lower() ), NavigableSet letsyoure-
turnsetviewscontainingallelementswithincertainranges,asdemonstratedbythefol-
lowing examples:
ns.subSet(-13, true, 9, true) : Return all elements from -13
through 9 .
ns.tailSet(-6, false) : Return all elements greater than -6 .
ns.headSet(4, true) : Return all elements less than or equal to 4 .
Finally,youcanreturnandremovefromthesetthefirst(lowest)elementbycalling
pollFirst() andthelast(highest)elementbycalling pollLast() .Forexample,
ns.pollFirst() removes and returns -13 , and ns.pollLast() removes and
returns -82 .
Queue
A queue is a collection in which elements are stored and retrieved in a specific order.
Most queues are categorized as one of the following:
First-in, first-out (FIFO) queue :Elementsareinsertedatthequeue's tail andre-
moved at the queue's head .
Last-in, first-out (LIFO) queue :Elementsareinsertedandremovedatoneend
of the queue such that the last element inserted is the first element retrieved.
This kind of queue behaves as a stack .
Priority queue :Elementsareinsertedaccordingtotheirnaturalordering,orac-
cording to a comparator that is supplied to the queue implementation.
Queue , whose generic type is Queue<E> , extends Collection , redeclaring
add() toadjustitscontract(insertthespecifiedelementintothisqueueifitispossible
Search WWH ::




Custom Search