Return type | Name and parameters |
---|---|
OptionalInt
|
filter(IntPredicate test)
If a value is present in the OptionalInt , tests the value using
the given predicate and returns the optional if the test returns true or
else empty.
|
int
|
get()
If a value is present in the OptionalInt , returns the value,
otherwise throws NoSuchElementException .
|
Optional
|
mapToObj(IntFunction mapper)
If a value is present in the OptionalInt , returns an Optional
consisting of the result of applying the given function to the value or else empty.
|
IntStream
|
stream()
If a value is present in the OptionalInt, returns an IntStream with the value as its source or else an empty stream. |
addShutdownHook
, any
, any
, asBoolean
, asType
, average
, collect
, collect
, collect
, contains
, count
, dump
, each
, eachWithIndex
, equals
, every
, every
, find
, find
, findAll
, findAll
, findIndexOf
, findIndexOf
, findIndexValues
, findIndexValues
, findLastIndexOf
, findLastIndexOf
, findResult
, findResult
, flatten
, getAt
, getMetaClass
, getMetaPropertyValues
, getProperties
, grep
, grep
, groupBy
, groupBy
, hasProperty
, identity
, inject
, inject
, inspect
, invokeMethod
, is
, isCase
, iterator
, join
, metaClass
, print
, print
, printf
, printf
, println
, println
, println
, putAt
, respondsTo
, respondsTo
, setMetaClass
, size
, split
, sprintf
, sprintf
, stream
, sum
, sum
, tap
, toArrayString
, toSpreadMap
, toString
, use
, use
, use
, with
, with
, withTraits
If a value is present in the OptionalInt
, tests the value using
the given predicate and returns the optional if the test returns true or
else empty.
assert !OptionalInt.empty().filter(i -> true).isPresent() assert OptionalInt.of(1234).filter(i -> true).isPresent() assert !OptionalInt.of(1234).filter(i -> false).isPresent() assert OptionalInt.of(1234).filter(i -> true).getAsInt() == 1234
If a value is present in the OptionalInt
, returns the value,
otherwise throws NoSuchElementException
.
assert OptionalInt.of(1234).get() == 1234
If a value is present in the OptionalInt
, returns an Optional
consisting of the result of applying the given function to the value or else empty.
assert !OptionalInt.empty().mapToObj(x -> new Object()).isPresent() assert OptionalInt.of(1234).mapToObj(x -> new Object()).isPresent() assert !OptionalInt.of(1234).mapToObj(x -> null).isPresent() assert OptionalInt.of(1234).mapToObj(Integer::toString).get() == '1234'
If a value is present in the OptionalInt, returns an IntStream with the value as its source or else an empty stream.