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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:01:44+00:00 2026-06-18T04:01:44+00:00

I hava an ArrayList that got filled from an SQL query and contains all

  • 0

I hava an ArrayList that got filled from an SQL query and contains all the rows of a table.

If I want a subset of this ArrayList (say WHERE column1 = x)
Is it faster to remake an SQL connection and fetch a query with this condition, or loop through the arraylist and filter the data ? (considering an arraylist of 1000 rows)

If the loop through the arraylist is faster, until what size is it still appliable ?

Thank you

  • 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-18T04:01:46+00:00Added an answer on June 18, 2026 at 4:01 am

    It should be always faster to do this in Java. Java filtering of a memory array is as fast as, or faster, than SQL. And you also have to consider the overhead of connecting to the database, sending the command, and decoding the answer.

    For really complex queries it could be simpler to have this done by SQL, and it probably scales better regarding to database size (think one million rows: are you going to keep them all in memory?). Also, the SQL query optimizer might have more information on column cardinality and be able to perform more efficiently, and therefore faster, overall, than your merely-faster-on-a-check-by-check-basis Java code.

    On the other hand, also consider maintainability of the code. Some things are better left to SQL even if they’re a mite slower that way.

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

Sidebar

Related Questions

i hava a c++ method(for java,jni) like follow,when i repeat call this from java
I hava a CSV file that I want to treat as source code. Essentially
I hava an application that has a register frame with all relavant textboxes and
I hava the sql as below: select a.dept, a.name from students a group by
I hava one string 2013-1-31 08:25 PM i want to split from space and
I hava an application that reads a file from a ZIP archive and saves
I hava very large table with 1373228 rows. I need to copy the result
I hava a xml doc (and complex element) that is similar to this example:
I hava a method setData(ArrayList<super> list) , so anyone who want set data can
I hava got 2 Threads in java and I want hook up them. I

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.