I could have this done in php in three lines of code but in Java here's what I need to do:
English
Looping through list of words I call a function that returns a HashSet of movie titles that contain that particular word. I want to insert these titles into a HashMap with their value being a counter of how many times this title occured.
(if two words return the same title, that title's value (counter) would be 2)
Relative Code: -
-
for(int i = 0; i < titleWords.length; i++ ) {
-
HashSet tempHash = (HashSet) hashtable.get( titleWords[i] );
-
-
// put result into hashmap and increment counter
-
Iterator myIt = tempHash.iterator();
-
int counter;
-
while(myIt.hasNext()) {
-
counter = 0;
-
String title = (String) myIt.next();
-
counter = (int) resultMap.get((String)myIt.next()); //*** ERROR: inconvertible types
-
resultMap.put((String)myIt.next(), ++counter);
-
}
-
}
-
-
-
That's where it sits now, I tried a few different ways, and obviously they did not work.
Since I can't sort a HashMap, would something else work better? if so, don't bother answering my question with a HashMap, answer it with another list/array implementor that can store key/value pairs.
Thanks for any pointers,
Dan