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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:14:57+00:00 2026-06-04T23:14:57+00:00

Java methods accepting and returning Iterable<T> types are very common. The problem I see

  • 0

Java methods accepting and returning Iterable<T> types are very common. The problem I see is that the Iterator interface is so limited, that it either requires one to reconstruct the Iterable into a usable data structure, or forces the users to perform multiple traversals of the Iterable, increase execution time.

Can someone correct me on this? Are Iterables as bad as I think they are? Are there any techniques that one can use to work-around the limitation of Iterables if you are forced to use them?

  • 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-04T23:14:59+00:00Added an answer on June 4, 2026 at 11:14 pm

    Regarding accepting an Iterable<T> this is clearly a good thing. It means you can pass it almost any data structure – it only needs to implement the very simple Iterable<T> interface. This makes the code easier to reuse.

    For returning an Iterable<T> one of the advantages is that the implementation of the method can change – perhaps using a more efficient data structure, or by generating the results lazily as they are requested (e.g. streaming them from disk). It is easy to change the implementation without breaking your clients, because they only depend on the Iterable<T> interface. If you had exposed a List<T> then you can’t be sure that your clients will access the data in sequential order.

    You are right that if you need to access the results more than once then it would make sense to first copy the data into a different structure. But only you know what specific collection is most useful for your specific situation. Sometimes it could be an ArrayList. Other times you might prefer to store the items in a HashMap. So you would often have to copy the data into a new data structure anyway.

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

Sidebar

Related Questions

Why was java defined such that methods may take as input multiple parameters, but
What methods do I need to add to a custom Java class so that
I came across this class java.io.FileSystem and noticed it has many methods that I
Are Java final methods automatically inlined? Many books says yes many books says no!!!
The examples for JNI i've seen map Java native methods to implementation by C++
In Java there are methods to go about scanning the classpath/all classes/within a package
why java Object class has two methods hashcode() and equals()? One of them looks
My Java class contains the following methods: public static void main(String[] argv) //start the
Given two methods on the same class in Java : public void doSomething( Person
i use java reflections to get methods used in a class.I also want to

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.