ArrayList is an implementation of a java.util.List collection backed by a dynamic array.
This means three things.
Firstly, you don't need to worry about resizing, allocating or coping elements into the array, the ArrayList will take care of it for you.
Secondly, any method that wants a List doesn't care about the implementation (you could pass a LinkedList instead) which decouples the code (meaning you can change the implementation without adversely effecting those who rely on it, because of the contract made through the List interface)
Thirdly, to interact with the contents of the List, you need to use one or more of the interfaces access methods.
You already know about add, but to obtaining an object, you need to use get which;
Returns the element at the specified position in this list
You might also be interested in
There are other methods, of course, but these are the immediately useful.
I'd also have a read through the Collections Trail
UPDATED example
public class Test {
public static void main(String[] args) {
new Test();
}
public Test() {
List<Book> listOfBooks = new ArrayList<Book>();
Book bk1 = new Book();
listOfBooks.add(bk1);
System.out.println(" bk1 = " + bk1);
System.out.println("listOfBooks(0) = " + listOfBooks.get(0));
}
public class Book {
String name;
int pages;
String auother;
boolean available;
String rentername;
@Override
public String toString() {
return "Book: name = " + name + "; pages = " + pages + "; available = " + available + "; rentername = " + rentername + "; hashCode = " + hashCode();
}
}
}
Which outputs
bk1 = Book: name = null; pages = 0; available = false; rentername = null; hashCode = 1137551390
listOfBooks(0) = Book: name = null; pages = 0; available = false; rentername = null; hashCode = 1137551390