imcompatible types

import java.util.ArrayList;

public class song

{

private String name;

private String artist;

private int length;

private String genre;

private ArrayList ar = new ArrayList();

private ArrayList genreAL= new ArrayList();

public song()//default constructor

{

}

public song(String myName, String myArtist, int myLength, String myGenre )

{

name=myName;

artist=myArtist;

length=myLength;

genre=myGenre;

}

public void song(song ex)

{

name=ex.name;

artist=ex.artist;

length=ex.length;

genre=ex.genre;

}

public void setName(String ex)

{

name=ex;

}

public void setArtist(String ex)

{

artist=ex;

}

public void setLength(int ex)

{

length=ex;

}

public void setGenre(String ex)

{

genre=ex;

}

public String toString()

{

return "Song name: " + name+ " artist: "+artist+ " length: " +length+" genre: "+genre;

}

public String getGenre()

{

return genre;

}

public ArrayList specificGenre(String certainGenre)

{

for (int i =0; i <ar.size();i++)

{

if( ((((song)ar.get(i))).getGenre()).compareTo(certainGenre))

genreAL.add(ar.get(i));

}return genreAL;

}

}

i get an error in the last method. Im trying to get all the songs with a certain genre into an arraylist. not sure if my logic is right but i get incompatible types, not sure what the error is. certainGenre is a string and (song)ar.get(i).getGenre() should get me the genre of the song which should be also a string. so im not sure>

[1747 byte] By [ImmortalKinga] at [2007-11-26 14:46:50]
# 1
Read this: http://forum.java.sun.com/help.jspa?sec=formattingArrayLiost.get() returns an Object-type reference. Your variable is of type String though. Object != String (although String == Object). You need to cast.
CeciNEstPasUnProgrammeura at 2007-7-8 8:34:31 > top of Java-index,Java Essentials,Java Programming...