Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By jim829

Thread: How come an iterator that is returned by the java collection framework is an object?

  1. #1
    raffs03 is offline Member
    Join Date
    Sep 2012
    Posts
    54
    Rep Power
    0

    Default How come an iterator that is returned by the java collection framework is an object?

    As the title says "How come an iterator that is returned by the java collection framework(e.g. arraylist) is an object if the Iterator interface cannot be instantiated?
    e.g. Iterator it = myArrayList.Iterator();
    Last edited by raffs03; 05-07-2018 at 04:11 AM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,209
    Rep Power
    12

    Default Re: How come an iterator that is returned by the java collection framework is an obje

    An iterator can be returned in many ways. A class Foo could implement the interface and return an instance of itself as a type Iterator. Or the class Foo could have a private class that could implement the interface and return an instance of the private class.

    Regards,
    Jim
    Last edited by jim829; 05-07-2018 at 06:05 PM.
    SurfMan likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    raffs03 is offline Member
    Join Date
    Sep 2012
    Posts
    54
    Rep Power
    0

    Default Re: How come an iterator that is returned by the java collection framework is an obje

    it's clear to me now thx man.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,209
    Rep Power
    12

    Default Re: How come an iterator that is returned by the java collection framework is an obje

    Geez. I just reread my reply. I'm surprised it was clear to you considering my grammar and typos (now fixed for posterity).

    Regards,
    Jim
    Last edited by jim829; 05-07-2018 at 02:56 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,965
    Rep Power
    7

    Default Re: How come an iterator that is returned by the java collection framework is an obje

    Quote Originally Posted by jim829 View Post
    Geez. I just reread my reply. I'm surprised it was clear to you considering my grammar and typos (now fixed for posterity).

    Regards,
    Jim
    You might wanna go back again and add the word "or" in between "instance" and "itself", so it reads: "instance of itself". Otherwise, great answer. :)
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,209
    Rep Power
    12

    Default Re: How come an iterator that is returned by the java collection framework is an obje

    I did just that. And even found another one. Thanks! :)

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 5
    Last Post: 09-17-2011, 01:35 AM
  2. Replies: 10
    Last Post: 05-21-2011, 01:47 PM
  3. collection framework
    By swati.jyoti in forum New To Java
    Replies: 8
    Last Post: 09-01-2009, 03:45 PM
  4. Java Collection Framework (Lists)
    By Java Tutorial in forum Java Tutorial
    Replies: 1
    Last Post: 05-16-2008, 01:44 PM
  5. Java Collection Framework (Sets)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 12-07-2007, 07:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •