예제 #1
0
 /**
  * Returns the first element in {@code iterable} that satisfies the given predicate, or {@code
  * defaultValue} if none found. Note that this can usually be handled more naturally using {@code
  * tryFind(iterable, predicate).or(defaultValue)}.
  *
  * @since 7.0
  */
 @Nullable
 public static <T> T find(
     Iterable<? extends T> iterable, Predicate<? super T> predicate, @Nullable T defaultValue) {
   return Iterators.find(iterable.iterator(), predicate, defaultValue);
 }
예제 #2
0
 /**
  * Returns the first element in {@code iterable} that satisfies the given predicate; use this
  * method only when such an element is known to exist. If it is possible that <i>no</i> element
  * will match, use {@link #tryFind} or {@link #find(Iterable, Predicate, Object)} instead.
  *
  * @throws NoSuchElementException if no element in {@code iterable} matches the given predicate
  */
 public static <T> T find(Iterable<T> iterable, Predicate<? super T> predicate) {
   return Iterators.find(iterable.iterator(), predicate);
 }