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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:13:10+00:00 2026-06-03T19:13:10+00:00

I´d just want to know your opinion regarding to change all the Collections function

  • 0

I´d just want to know your opinion regarding to change all the Collections function output to an Iterable type.

This seems to me probably the most common code in Java nowadays, and everybody returns always a List/Set/Map in 99% of times, but shouldn´t be the standard returning something like

    public final Iterable<String> myMethod() {
            return new Iterable<String>() {
                  @Override
                  public Iterator<String> iterator() {return myVar.getColl();}
            };
    }

Is this bad at all? You know all the DAO classes and this stuff would be like

    Iterable<String> getName(){}
    Iterable<Integer> getNums(){}
    Iterable<String> getStuff(){}

instead of

    List<String> getName(){}
    List<Integer> getNums(){}
    Set<String> getStuff(){}

After all, 99% of times you will use it in a for loop…

What dod you think?

  • 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-03T19:13:12+00:00Added an answer on June 3, 2026 at 7:13 pm

    This would be a really bad plan.

    I wouldn’t say that 90% of the time you just use it in a for loop. Maybe 40-50%. The rest of the time, you need more information: size, contains, or get(int).

    Additionally, the return type is a sort of documentation by itself. Returning a Set guarantees that the elements will be unique. Returning a List documents that the elements will be in a consistent order.

    I wouldn’t recommend returning specific collection implementations like HashSet or ArrayList, but I would usually prefer to return a Set or a List rather than a Collection or an Iterable, if the option is available.

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

Sidebar

Related Questions

This isn't exactly a programming question exactly. I just want to know what your
I just want to know what is your opinion about how to fingerprint/verify html/links
I just want to know whether you need robots.txt in your website for the
Just want to know how do you guys provide this files for the users.
Just want to know if publishing an application on Google play is allowed using
Just want to know how to read an attribute of a parent node from
I just want to know why both the paint and draw methods are used
i just want to know, how to write Code behind(Hyperlink1_Click()), for the hyper link
I just want to know what is the actual difference between private and protected
I just want to know how to access an array in SMARTY that have

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.