Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 871291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:37:12+00:00 2026-05-15T10:37:12+00:00

I love Google Guava and use it a lot, but there is one method

  • 0

I love Google Guava and use it a lot, but there is one method I always find me writing..

 public static <T> T tryFind(Iterable<T> iterable, Predicate<T> predicate){
     for(T t : iterable){
         if(predicate.apply(t)){
              return t;
         }
     }
     return null;
  }

To me this seems to be a very useful addition to Iterables (also to Iterators for that matter), so I’m wondering why it’s missing. Also, while I can see the point of having a method that throws NoSuchElementException, perhaps to distinguish between finding a null and not finding the element, that situation only comes up if the predicate you are using is

public boolean apply(T t){
     return t==null;
}

which doesn’t seem to be a common case.

So why did guava designers chose to have this behavior, instead of just returning null if it can’t find it?

Here is the javadoc for [Iterables.find()][1]

[1]: http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Iterables.html#find(java.lang.Iterable, com.google.common.base.Predicate)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:37:12+00:00Added an answer on May 15, 2026 at 10:37 am

    We’re adding another overload of find() which accepts a default value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would love to use google document viewer , but I am dealing with
I love scaffolding and it extremely helpful for prototyping. But Should we use scaffolding
I'd love to Google this (I've tried) but I'm not sure what it is
I love that Microsoft and Google are embracing jQuery but is this good? How
I've started messing around with Google App Engine, writing Python. I love Visual Studio
I'd love to use Google Caja to run user-submitted Javascript 'live demos' in a
I'm writing a Bookmarklet to change the behaviour of the google homepage. I love
I love vim and the speed it gives me. But sometimes, my fingers are
I love the way I can profile a Java/.Net app to find performance bottlenecks
I love the Ruby RSpec BDD development style. Are there any good tools for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.