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 8152111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:37:09+00:00 2026-06-06T15:37:09+00:00

Using Lambdaj, I am trying to isolate, from a list, an object that satisfies

  • 0

Using Lambdaj, I am trying to isolate, from a list, an object that satisfies 2 separate criteria. Both of the following will achieve my goal.
A)

    List<SomeObject> someObjectsWithMatchingSomeObjectIds = select(foo.getSomeParentObject().getSomeObjects(), having(on(
            SomeObject.class).getId(), equalTo(123)));
    SomeObject someObject = selectFirst(someObjectsWithMatchingSomeObjectIds, having(on(SomeObject.class).getLoanTerm(),
            notNullValue()));

B)

    SomeObject someObject = selectFirst(select(foo.getSomeParentObject().getSomeObjects(), having(on(SomeObject.class)
            .getId(), equalTo(123))), having(on(SomeObject.class).getLoanTerm(), notNullValue()));

The first one seems more readable, particularly for people who are not familiar with the API. The second one seems to harness the functional programming aspect of lambdaj, which is best?

Readability wins I suppose. However, I wonder, is there a more concise way to handle two separate conditions when filtering a collection, using LambdaJ?

  • 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-06-06T15:37:11+00:00Added an answer on June 6, 2026 at 3:37 pm

    Removing intermediate definitions is not “more in the spirit” of much anything, and in general hurts readability. Having an intermediate definition helps having each line of the program simpler to read, and can be a great readability help when you can give the identifier a meaningful name — not sure it’s really the case in your code.

    You could have a readability win, I think, by not applying two filtering operations, select and then selectFirst, but using only one operation that combines the two matching condition with an and (beware, code not tested):

    SomeObject someObject = selectFirst(foo.getSomeParentObject().getSomeObjects(),
                                        and(having(on(SomeObject.class).getId(), equalTo(123)),
                                            having(on(SomeObject.class).getLoanTerm(), notNullValue()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write an extension method that will give me the MemberInfo representing
I am trying to implement the Maybe monad from Haskell using the lambda functions
I'm trying to sort a list of entities using a GridView in ASP.NET, but
trying to get my head around using Lambda expressions to fetch data from my
i am trying to call an parameterized constructor from an expression instead of using
Is it possible to write the folowing using lambda(C#) private static void GetRecordList(List<CustomerInfo> lstCustinfo)
In my repository implementation I can run the following query using a lambda expression:
I am using the following code to pass a property to a lambda expression.
I'm developing a API that uses lambda expressions to specify properties. I'm using this
I am trying to write the following double sum_res = 0.0; double yhat =

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.