public E peek ( ) { lock . lock ( ) ; try { if ( open ) { if ( elements . size ( ) > 0 ) { return elements . getFirst ( ) ; } else { return null ; } } else { throw new IllegalStateException ( "queue is closed" ) ; } } finally { lock . unlock ( ) ; } }
Returns the queue s next element without removing it if the queue is non - empty . Otherwise returns null .