Results 1 to 3 of 3
  1. #1
    KReative is offline Member
    Join Date
    Oct 2011
    Posts
    7
    Rep Power
    0

    Default listIterator question

    Hello,

    Can anyone please explain to me:
    How does the following code work:
    Iterator<String> li = l.listIterator(l.size());

    I tried replacing this with:
    Iterator<String> li = l.listIterator();
    li(l.size());

    however the second one doesn't work.

    Can anyone tell me why?

    I not trying to do anything specific, just trying to understand this...

    Thanks

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

    Default Re: listIterator question

    All you have to do is read the API documentation for the List and ListIterator interfaces; a List can give you a ListIterator starting at a certain index; a ListIterator doesn't have something like li(l.size()); (what is it anyway?)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    KReative is offline Member
    Join Date
    Oct 2011
    Posts
    7
    Rep Power
    0

    Default Re: listIterator question

    I am making a method to reverse a list.

    This is my working code:

    private static void reverseMe(List<String> l){
    ListIterator<String> li = l.listIterator(l.size());
    while(li.hasPrevious())
    System.out.printf("%s ", li.previous());
    }

Similar Threads

  1. Replies: 1
    Last Post: 06-08-2010, 09:58 AM
  2. Replies: 9
    Last Post: 04-11-2010, 07:43 PM
  3. ListIterator implementation
    By hari.kr in forum Advanced Java
    Replies: 2
    Last Post: 02-15-2010, 09:14 AM
  4. Bidirectional Traversal with ListIterator
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:37 PM
  5. using ListIterator with ArrayList
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-13-2007, 10:18 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
  •