public final T single ( ) { Iterator < T > it = iterator ( ) ; if ( it . hasNext ( ) ) { T v = it . next ( ) ; if ( it . hasNext ( ) ) { throw new IndexOutOfBoundsException ( "The source has more than one element." ) ; } return v ; } throw new NoSuchElementException ( "The source is empty." ) ; }
Returns the single element of this sequence or throws a NoSuchElementException if this sequence is empty or IndexOutOfBoundsException if this sequence has more than on element