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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:23:40+00:00 2026-05-11T16:23:40+00:00

Is there a way in Apache Commons Collections to have a PredicatedList (or similar)

  • 0

Is there a way in Apache Commons Collections to have a PredicatedList (or similar) which does not throw an IllegalArgumentException if the thing you are trying to add doesn’t match the predicate? If it does not match, it would just ignore the request to add the item to the list.

So for example, if I do this:

List predicatedList = ListUtils.predicatedList(new ArrayList(), PredicateUtils.notNullPredicate());
...
predicatedList.add(null); // throws an IllegalArgumentException 

I’d like to be able to do the above, but with the adding of null being ignored with no exception thrown.

I can’t figure out from the JavaDocs if Commons Collections supports this. I’d like to do this if possible without rolling my own code.

  • 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-11T16:23:40+00:00Added an answer on May 11, 2026 at 4:23 pm

    Just found CollectionUtils.filter. I can probably rework my code to use this, although it would still have been nice to quietly prevent the additions to the list in the first place.

        List l = new ArrayList();
        l.add("A");
        l.add(null);
        l.add("B");
        l.add(null);
        l.add("C");
    
        System.out.println(l); // Outputs [A, null, B, null, C]
    
        CollectionUtils.filter(l, PredicateUtils.notNullPredicate());
    
        System.out.println(l); // Outputs [A, B, C]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to apache commons-exec. Is there a way I can send a
I'm just wondering is there any way in the Apache Commons CLI library to
Is there a way to actively serve Apache's default, built-in 404 page for a
Is there a way to set php running under apache to create folders with
Is there way to copy a file into Plone with WebDAV and have Plone
I have a project that uses Apache Commons Logging & log4j with a large
The Java class CircularFifoBuffer in the package org.apache.commons.collections.buffer is non-generic, and can store objects
I've been trying to grok the org.apache.commons.beanutils library for a method/idiom to evaluate for
I'm trying to use Apache Commons Configuration and using ant for my build tool.
I am trying to get the Apache Commons HttpClient library (version 3.1) to ignore

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.