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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:55:52+00:00 2026-06-13T17:55:52+00:00

This other topic on Stack Overflow, traditional for loop vs Iterator in Java ,

  • 0

This other topic on Stack Overflow, “traditional for loop vs Iterator in Java“, discusses the performance difference between using indexes and using iterators. The top answer points out that there’s a very significant difference (a factor of 60.000) when dealing with containers such as LinkedList.

I expect this has something to do with caching. If that’s so, how do iterators get around this issue? If it has nothing to do with cache misses, what is it that makes iterators for non-contiguous containers so much faster?

  • 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-13T17:55:53+00:00Added an answer on June 13, 2026 at 5:55 pm

    The difference for linked lists isn’t any constant factor – it’s the difference between “a step” taking O(1) or O(N). (So the bigger the list, the bigger the difference.)

    An iterator retains whatever state it needs to “take the next step”. For a linked list, taking the next step means just following a reference from one node to the next… whereas accessing an element by index means starting at the head and executing the same “move next” step that many times.

    Compare that with ArrayList, where the iterator just needs to remember the current index, and then both “random access” and “sequential” access involve simply going straight to the right element of the array.

    So it’s not really caching as such – it’s retaining state. Whether an iterator is faster than access by index depends on what that access by index has to do. In the case of ArrayList, it’s cheap. In the case of LinkedList, it’s not.

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

Sidebar

Related Questions

My colleague wrote the following stackoverflow question: other stack overflow question on this topic
I know this topic has been discussed before on Stack Overflow. But there are
this topic has been touched multiple times on Stack Overflow, but my search still
There are several other questions about this topic that I have gone through, but
I've read the other posts here about this topic, but I can't seems to
I have seen some of the other answers on this topic but dont really
May a DTO have relations to other DTOs? Any more opinions on this topic
This question is similar to this other one , with the difference that the
I've looked through the other Stackoverflow questions on this topic and none of the
Note: This is closely related to my other topic here and here , but

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.