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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:29:17+00:00 2026-06-10T12:29:17+00:00

I have a large collection with many entries: Set<File> allFiles . Is it practical

  • 0

I have a large collection with many entries: Set<File> allFiles.

Is it practical to iterate through this Set using the following algorithm? Are there better ways to do it?

Set<File> allFiles = // ...100,000+ entries
Set<File> filteredList = new LinkedHashSet<File>();

FileNameExtensionFilter filter = new FileNameExtensionFilter("Extensions accepted", "a", "b", "c");

for (File file : allFiles) {
    if (filter.accept(file)) {
        filteredList.add(file);
    }
}

In case anyone is asking, the allFiles Set is pre-populated elsewhere, and not necessarily gleaned using the File.listFiles() method.

  • 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-10T12:29:19+00:00Added an answer on June 10, 2026 at 12:29 pm

    If by practical you mean writeable in 5 lines in java yes it is. There is no cleaner alternatives when you want to filter a list (as opposed to languages with functional constructs like Scala and its filter method).

    I personaly do not see how you could do it better, if your use case is really to filter out files with bad extensions I would do the same in Java.

    If you are worried to use interfaces and classes from javax.swing you should not, both these classes depend only on java.io or java.util.Locale (for setting file name to lowercase according to english locale), so they are as clean as the FilenameFilter from java.io. If your deal is really to filter according to case insensitive extension you should definitely go this way, the only alternative my eclipse sees is com.google.gwt.thirdparty.guava.common.io.PatternFilenameFilter implementing java.io.FilenameFilter, but then you have a new dependency and you write a Regex pattern which is far less readable and maintainable than your extensions. So I would stay with FileNameExtensionFilter if this is really your use case.

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

Sidebar

Related Questions

I have a very large .json file on disk. I want to instantiate this
We have a large internal data collection website. I don't have time to create
I have a dataset consisting of a large collection of points in three dimensional
I have a large (more than 100K objects) collection of Java objects like below.
I have a large collection (~2.7 million documents) in mongodb, and there are a
I have a large solution containing many projects with one of them being a
Currently i have the following syntax (list is a list containing objects with many
We have a large collection of MOSS 2007 sites that need a chunk of
My large (120gb) music collection contains many duplicate songs, and I've been trying to
I have a quite large codebase. In many places I have a piece of

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.