I would have done something along the line of:
import java.util.ArrayList;
class Book
{
int bookid;
String author;
String title;
}
class BookReader {
public static void main(String[] args)
{
Hashtable<String, Book> booklist = new Hashtable<int, Book>(); //now you can search with just the bookid
Book a = new Book();
a.bookid = 1;
a.author = "welcome";
a.title = "home";
booklist.putt(a.bookid, a);
Book b = new Book();
b.bookid = 2;
b.author = "welc";
b.title = "ho";
booklist.put(b.bookid, b);
for(Book book : booklist) //now you have the object directly available and can easily work with the object :)
{
String booktitle = (String)book.title;
String bookauthor = (String)book.author;
System.out.println("The book "+booktitle+" was written by: "+bookauthor);
}
}
}
ps. im at work right now so dont mind the possible syntax errors.