-1

I am trying to iterate over a list using listIterator:

import java.util.*;

public final class FindMeetingQuery {
        public Collection<TimeRange> query(Collection<Event> events, MeetingRequest request) {
            Collection<TimeRange> free = new ArrayList<TimeRange>(); //when user is free
            ListIterator<Event> iterator = events.listIterator();
            while (iterator.hasNext()) {
                     ...

However, I keep getting the error cannot find symbol: method listIterator(). Any help on this would be greatly appreciated.

  • 1
    even though `free` is an instance of `List` you've declared it (the variable) to be a `Collection` which doesn't define the `listIterator()`, change `Collection` to `List` – Lino Jun 29 '20 at 13:27
  • `Collection`class doesn't have a `listIterator()` method. Either use `iterator()` or use a different type of collection. – jhamon Jun 29 '20 at 13:28

1 Answers1

1

The Collection interface does not provide the listIterator method. It is, however, defined in other classes of the Java Collection Framework, such as ArrayList. You should change the type of the events variable if you want to use it.

gscaparrotti
  • 663
  • 5
  • 21