Results 1 to 5 of 5
  1. #1
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    162
    Rep Power
    6

    Default what is the differnce between Iterable & Iterator

    hi
    what is the differnce between Iterable & Iterator

    please explain it with example if any body can


    thankyou

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by javastuden View Post
    hi
    what is the differnce between Iterable & Iterator

    please explain it with example if any body can


    thankyou
    The API documentation explains it; why not read it? (hint: an Iterable can produce an Iterator).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    162
    Rep Power
    6

    Default thanks for reply

    hi, thanks for reply

    i know the documentation will describe it,i want to know what is the differnce between Iterable & Iterator means where to use iterator with iteratable


    thanks

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by javastuden View Post
    i know the documentation will describe it,i want to know what is the differnce between Iterable & Iterator means where to use iterator with iteratable
    An Iterable is able to give you an Iterator; note that other classes may be able to do the same. If you have an Iterable you can use an advanced for loop because the compiler knows about Iterables. There is nothing more to say about Iterables in combination with Iterators.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    This is a classic example of an interface vs a concrete class. Usually object types ending in 'able' (Iterable, Comparable, etc...) are objects that implement some interface which guarantees a certain collection of methods will be available. An Iterator itself is a concrete object which is use for the iterations. As JosAH said, a class which implements Iterable is guaranteed to be iterable (it comes with methods to perform iteration - return an Iterator), and can be referred to by the generic interface type of Iterable.

Similar Threads

  1. Problem implementing java.util.Iterable
    By ozzyman in forum New To Java
    Replies: 2
    Last Post: 04-05-2011, 12:12 AM
  2. Iterator
    By Dayanand in forum New To Java
    Replies: 2
    Last Post: 03-10-2011, 01:17 PM
  3. Replies: 0
    Last Post: 05-18-2010, 01:53 AM
  4. what is the differnce btw Ejb 3.0 and Ejb2.0
    By ravi.ch01 in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 09-28-2009, 02:32 PM
  5. Differnce Between JDK1.5 to JDK1.6
    By kallamrajareddy in forum New To Java
    Replies: 2
    Last Post: 03-12-2009, 08:43 AM

Posting Permissions

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