hasPrevious() Method not working

I don't understand why my hasPrevious iterator is not functioning, it looks like this:

public void previousSong(){
    Iterator<Song> iterator = songs.iterator();
if(iterator.hasPrevious()) {
        System.out.println(iterator.previous().toString());
}
}

I have another function using hasNext() and it works, but this one will not.

public void nextSong(){
    Iterator<Song> iterator = songs.iterator();
if(iterator.hasNext()) {
        System.out.println(iterator.next().toString());
}
}

I am not sure if this method is no longer in existence or not, but when I look into it, Java websites speak of it. I don't understand why it is not functioning.

Answers


The hasPrevious and previous methods are only defined for ListIterators (http://docs.oracle.com/javase/1.5.0/docs/api/java/util/ListIterator.html), a sub-interface of Iterator. As you're only using an Iterator the only defined methods are hasNext(), next and remove - see here: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Iterator.html.


Need Your Help

Highcharts multiple x-Axis without multiple series?

javascript highcharts axes multiple-axes

This fiddle uses multiple series and displays an axis for each of them. Is it possible to use a single series to make several Axes?

Static function as eventhandler in xaml

c# xaml silverlight-4.0 event-handling

I am using this code to simulate the tab functionality in my silverlight application.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.