Reading API for ArrayList
I have this class from my notes:
import java.util.*;
public class SongCollection
{
private String colName;
private ArrayList songNames;
public SongCollection(String colName)
{
this.colName = colName;
songNames = new ArrayList();
}
public String getColName()
{
return colName;
}
public void setColName(String colName)
{
this.colName = colName;
}
public ArrayList getSongNames()
{
return songNames;
}
public void addSong(String song)
{
songNames.add(song);
}
public boolean hasSongName(String song)
{
return (songNames.contains(song));
}
public boolean removeSongName(String song)
{
return (songNames.remove(song));
}
public String toString()
{
return ("Song collection: " + colName);
}
}
public static void main(String[] args)
{
SongCollection2 popCollection = new SongCollection2("Collection");
popCollection.addSong("Classic");
popCollection.addSong("Dance");
popCollection.addSong("Music");
popCollection.addSong("Jazz");
System.out.println(popCollection.getSongNames());
System.out.println(popCollection.removeSongName("D ance"));
System.out.println(popCollection.getSongNames());
}
It use the ArrayList class. I am wondering from the methods "songNames.remove()", "songNames.add{}", "songName.contain()", why the API does not state that it can grab the String input but this program can run and perform without any error?
From the API
boolean add(E e)
Appends the specified element to the end of this list.
void add(int index, E element)
Inserts the specified element at the specified position in this list.
E remove(int index)
Removes the element at the specified position in this list.
boolean remove(Object o)
Removes the first occurrence of the specified element from this list, if it is present.
boolean contains(Object o)
Returns true if this list contains the specified element.