Unable to iterate Java List in Scala

I’m using the Java Twitter4J library in a Scala project.

I’m calling the method


This method returns a list of twitter4j.User objects containing statuses.

I try to iterate over them and it goes in an infinite loop over the first element:

val users:List[User] = twitter.getFriendsStatuses(userId, paging.getSinceId())
while( users.iterator.hasNext() ) {

Any ideas?


I guess users.iterator produces the new iterator each time it’s evaluated. Try this:

val it = users.iterator
while(it.hasNext() ) {

Leave a Reply

Your email address will not be published. Required fields are marked *