I have a Java assignment where we are to program a "database" of books and journals using the ArrayList class to store them as objects of type Reference.
One of the requirements from this assignment is that we split the titles of the books in the database and save them into a HashMap to allow for keyword searching later.
My hashmap is declared like this:
private HashMap <String, Reference> titles = new HashMap <String,Reference> (10);
I know through testing that the way I add titles and References to the HashMap works. What does not work is my search function.
private void searchBooks(String callNumber, String[] keywords, int startYear, int endYear) {
Set<String>commonKeys = new HashSet<String>();
for(int i = 0; i < keywords.length; i ++)
{
commonKeys.add(keywords[i]);
}
titles.keySet().retainAll(commonKeys);
System.out.println(titles);
This is code I've pieced together based off of my knowledge, and similar problems I've been able to find on this sites various threads.
Am I approaching this right? Is there something I'm missing?