I have a Song class(field: String name) and an Album class (initialize an Arraylist fill with Song objects), I am adding a method (addSongAlbum(String name parameter))that first check if the song is already in the album. Everything works fine but now I want to check too if the song exist outside the album. How can I do this taking in consideration that the input of the method is a String?
public void addSongToAlbum(String name){
if(checkExist(name) == null){
album.add(checkExist(name));
System.out.println("Song "+name+" was successfully added");
} else {
System.out.println("This song is already in the album");
}
}
private Song checkExist(String name){
for(int i=0; i<album.size(); i++){
if(name.equals(album.get(i).getName())){
return album.get(i);
}
}
return null;
}