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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:23:01+00:00 2026-05-17T00:23:01+00:00

Is there a construct in java that does something like this(here implemented in python):

  • 0

Is there a construct in java that does something like this(here implemented in python):

[] = [item for item in oldList if item.getInt() > 5]

Today I’m using something like:

ItemType newList = new ArrayList();
for( ItemType item : oldList ) {
    if( item.getInt > 5) {
     newList.add(item);
    }
}

And to me the first way looks a bit smarter.

  • 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-17T00:23:02+00:00Added an answer on May 17, 2026 at 12:23 am

    Java 7 might or might not implement closures and hence support functionality like this, but currently it doesn’t, so on the Java VM you have the options to do it in Groovy, Scala or Clojure (possible others, too), but in java you can only get close to that by using helpers like Guava’s Collections2.filter().

    JDK 7 sample code:

    findItemsLargerThan(List<Integer> l, int what){
       return filter(boolean(Integer x) { x > what }, l);
    }  
    findItemsLargerThan(Arrays.asList(1,2,5,6,9), 5)
    

    Groovy sample code:

    Arrays.asList(1,2,5,6,9).findAll{ it > 5}
    

    Guava Sample Code:

    Collections2.filter(Arrays.asList(1, 2, 5, 6, 9),
        new Predicate<Integer>(){
            @Override
            public boolean apply(final Integer input){
                return input.intValue() > 5;
            }
        }
    );
    

    Scala sample code (thanks Bolo):

    Array(1, 2, 5, 6, 9) filter (x => x > 5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering if there is any JPQL construct that might help me with this
Is there an add-in for the VSIDE that allows you to visually construct ASP.NET
I'm building an application whose usage is going to look something like this: application
I noticed that every tutorial on how to do JavaScript inheritance does this: SubClass.prototype
Possible Duplicates: Why does this go into an infinite loop? Things like i =
I have an application that uses several different Java classes and would like to
Is there any sense to declare default constructor in Java? class MyClass { public
Is there a way construct a predicate to filter by class type? I currently
Is there any way I can construct an new object from the given object
is there any tool or utility(mapper assembly) to construct business objects from entities(which are

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.