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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:09:47+00:00 2026-05-15T02:09:47+00:00

What is Iterator and collections? Does these two have any relations? // the interface

  • 0

What is Iterator and collections?
Does these two have any relations?

// the interface definition
Interface Iterator {
    boolean hasNext();
    Object next(); // note "one-way" traffic
    void remove();
}

// an example
public static void main (String[] args){
    ArrayList cars = new ArrayList();

    for (int i = 0; i < 12; i++)
        cars.add (new Car());

    Iterator it = cats.iterator();

    while (it.hasNext())
        System.out.println ((Car)it.next());
}

Does the Interface Iterator has these method names alone predefined or its user defined?.
What does these four lines below actually tell?

cars.add (new Car());
Iterator it = cats.iterator();
while (it.hasNext())
    System.out.println ((Car)it.next());

Thanks. I am going through a book in collections.

  • 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-05-15T02:09:47+00:00Added an answer on May 15, 2026 at 2:09 am

    The Java collections are, as the name says, collections of things. If you don’t know that word, look it up in a dictionary.

    There are many types of collections. Take for example the mathematical concept of a set. You can put arbitrary things in a set, but it will never contain the same thing more than once. The things in the set are not ordered, that is you cannot say A comes before B. Another type of collection is a list. A list can contain the same thing more than once, and the order of the things in the list is important.

    What all these collections have in common is that they contain things, which in Java are called elements. When you want to know which things are in a certain collection, you iterate over the collection, which is just another term for going through all elements. This is what an Iterator does. It basically starts at the beginning of a collection, you can always ask whether there is a next element (hasNext()), and if there is, you can get access to that element (next()), until you have iterated over all elements in the collection.

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

Sidebar

Related Questions

I have an object: map<A*, string> collection; I would like to call the map::find
If Collection defines hasNext() instead of iterator().hasNext() , we could write loop easier: while(collection.hasNext()){…}
According to the documentation on ABCs , I should just have to add a
I want a convenient way to generate an Iterable , given a initial object
For small collections std::vector is almost certainly the best container whatever the operations applied
I am making an encrypt and decrypt program for my programming class, however I
For a php project I use a Collection class to handle my objects and
Possible Duplicate: Examples of GoF Design Patterns At an interview a while back I
There was a question asked about how to sort a List. There were several
ListSet (collection.immutable.ListSet) is a inverse ordered set. I need ordered set. This is a

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.