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

  • Home
  • SEARCH
  • 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 8882619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:37:29+00:00 2026-06-14T20:37:29+00:00

What would be faster to find a match: iterate over a list, or perform

  • 0

What would be faster to find a match: iterate over a list, or perform a JPQL query? On average of course, because this also depends on where the match is in the list. Would the answer depend on the list size?

Example: find the Person with name “Joe” (unique name)

JPQL:

TypedQuery<Person> q = em.createQuery(  "SELECT p " +
                                        "FROM Person p " +
                                        "WHERE p.name = :name ", Person.class);
q.setParameter("name", "Joe");
return q.getResultList().size() == 1;

Iterate:

for (Person p : persons) {
    if ("Joe".equals(p.name)) {
        return true;
    }
}
return false;
  • 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-14T20:37:30+00:00Added an answer on June 14, 2026 at 8:37 pm

    Whether the finding the specific person will be faster in Java or the DB is really dependent on your specific situation and if you’re having problems with performance here, you should really just time both implementations.

    There are a bunch of things to consider. A big one is, where does persons come from in your iteration example? Do you already have a list of people on hand, or do you have to SELECT all the people out of the db right before that? If you are going to query the Person table anyway, you’re probably better off just throwing that simple where clause on.

    Also, the number of results may matter if there are a lot. If you only have 5 people in your db then any difference in implementation speed will probably be so small you won’t notice. If you have a couple million then those differences will be amplified.

    My gut feeling is that it probably doesn’t make a significant difference either way for your case and you should use whichever you are more comfortable with. If this is really a performance bottleneck though, then you need to time them both before you start worrying about fiddling with tables, indexes, threading, whatever.

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

Sidebar

Related Questions

I'm looking for a single-producer, single-consumer FIFO implementation that would perform faster than the
Is there a way to make this query faster: $qur = mysql_query( SELECT id,
For example,We have a DWORD = $12345678 Which of the instructions would be faster
I would like to know if ParseExact is faster than Parse. I think that
I would like to know what performs faster and its preferable a condition in
I am wondering which way would end up being faster, selecting elements by: $('element[href=#my_link]');
What is faster: Function pointers or switch? The switch statement would have around 30
Would be possible to extend this kind of layout so that I can have
The SQL index allows to find quickly a string which matches my query. Now,
The Issue Cannot believe I could not find anything on this around the net,

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.