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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:07:59+00:00 2026-06-04T15:07:59+00:00

Even if only List and Set implement the interface Iterable , I believe that

  • 0

Even if only List and Set implement the interface Iterable, I believe that an array, a list, a set and a map are all iterable objects, in that we can use them all through a foreach loop:

for(String s : new String[0]);
for(String s : new ArrayList<String>());
for(String s : new HashSet<String>());
for(Entry<Integer, String> entry : new HashMap<Integer, String>().entrySet());

The case of Map is maybe a bit different, but let consider it as a key-value list (what it actually is).

Starting with that iterable understanding, am I missing a type in the following method?

public boolean isIterable(Object o) {
    return o instanceof Object[] || o instanceof Iterable || o instanceof Map;
}

In other words, are there any other types that can be iterated through a foreach loop?

Side but resulting question: is that list of types exhaustive?

  • 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-04T15:08:01+00:00Added an answer on June 4, 2026 at 3:08 pm

    Anything that implements the Iterable<T> interface is iterable. The Iterable API lists many of the core Java classes that do this. And note that this also includes class that you create that implement the interface. I’ve done this at times if my class contains an ArrayList or other iterable object and I want to conveniently iterate through the contents of this. I simply pass the list’s Iterator object as the return result for the iterator() method.

    For example:

    Person.java

    class Person {
       private String lastName;
       private String firstName;
       public Person(String lastName, String firstName) {
          this.lastName = lastName;
          this.firstName = firstName;
       }
       @Override
       public String toString() {
          return "Person [lastName=" + lastName + ", firstName=" + firstName + "]";
       }
    
    
    }
    

    MyPeople.java

    class MyPeople implements Iterable<Person> {
       List<Person> personList = new ArrayList<Person>();
    
       // ... other methods and constructor
    
       @Override
       public Iterator<Person> iterator() {
          return personList.iterator();
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've optimized my code to use only lightweight libraries. I'm even using the low
i have a php loop which displays only one record even if there is
The Product Tags tab would only appear after a product has been created. Even
I am passing three feields but only the first one is being passed even
For some reason my galleryScroll() function only runs once, even though the function calls
I have multiple messages in SQS. The following code always returns only one, even
Even though it's not part of HTTP 1.1/RFC2616 webapps that wish to force a
Suppose I want to add functionality like map to a Scala List , something
I have a list of stories defined and, in another table, a set of
In a controller I have two values: public List<String> StringValue {get; set;} public List<String>

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.