Results 1 to 6 of 6
  1. #1
    katturv is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default collection class in java

    why ArrayList can use only Iterator to access the elements???
    where as Vector uses both

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

    Default

    Quote Originally Posted by katturv View Post
    why ArrayList can use only Iterator to access the elements???
    where as Vector uses both
    I don't know what you mean: both the ArrayList and Vector class extend from the AbstractList class which provides the iterators: an Iterator and a ListIterator ... please elaborate.

    kind regards,

    Jos

  3. #3
    katturv is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Thumbs up

    Hi,

    i was reading an article for differences between arraylist and vector
    and i found the below answer
    ArrayList can use only Iterator to access the elements. Vector list can use Iterator and Enumeration Interface to access the elements.

    article site::Java Interview Questions Core Java Interview Questions Java FAQs AJAX FAQs AJAX Tutorials AJAX Tutorials JSF Hibernate Struts iBatis FAQs
    so wanted to knw

  4. #4
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default

    Quote Originally Posted by http://download.oracle.com/javase/6/docs/api/java/util/Enumeration.html
    NOTE: The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.
    arraylist exists since 1.2
    vector since 1.0

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,998
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by katturv View Post
    Hi,

    i was reading an article for differences between arraylist and vector
    and i found the below answer
    ArrayList can use only Iterator to access the elements. Vector list can use Iterator and Enumeration Interface to access the elements.

    article site::Java Interview Questions Core Java Interview Questions Java FAQs AJAX FAQs AJAX Tutorials AJAX Tutorials JSF Hibernate Struts iBatis FAQs
    so wanted to knw
    An Enumeration is a (more or less) legacy class. The Vector class could create an Enumeration over its elements long before the collections existed. The collections came with the (better) Iterator interfaces and the Vector class was retrofitted in the collections framework and it had to keep its Enumeration to keep old code alive.

    kind regards,

    Jos

  6. #6
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    4

    Default

    Read the Enumeration API entry to find out why this doesn't matter, and why Oracle wants you to use Iterator in place of Enumeration:
    Enumeration API

    NOTE: The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.
    edit: ¡Ay, caramba! I'm slow!

Similar Threads

  1. java collection api
    By rajinder5 in forum Advanced Java
    Replies: 1
    Last Post: 10-07-2010, 01:51 PM
  2. java collection arraylist in jdk 1.4
    By jagdish_ in forum Advanced Java
    Replies: 1
    Last Post: 06-12-2010, 02:19 PM
  3. Java Collection class & methods
    By box2box in forum New To Java
    Replies: 2
    Last Post: 05-26-2010, 01:51 AM
  4. know the class coming under the collection api in java
    By javastuden in forum New To Java
    Replies: 1
    Last Post: 11-24-2009, 07:10 AM
  5. Collection - java
    By Moonlightkid in forum Advanced Java
    Replies: 3
    Last Post: 09-02-2008, 05:04 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
  •