In Java, how can I create an array where each element is a list of objects containing a pair of keys.
Then given an index of this array, I should be able to search the list at the index provided a single key value and retrieve the corresponding value.
Problem Statement
I have around 2 million webpage name and corresponding to each name are categories (one or more) .
I can hash them down to say 1,00,000 using some hash function but obviously their will be collisions.
I want to build a data structure in Java that can store all this information, and then given a webpage and then, after hashing, given the index, I can find the categories of the web page.
It sounds like what you want is an array of maps:
This is how you add a map:
This is how you add
valueto the map at indexiwithkeyas key:To search for
keyin the map at indexiuse:Edit: After your edit I think that the solution to your problem is to simply use
HashMap<String, List<String>>. You’d use the name of thewebpageas key and the list of category-names as values. There is no need to implement your own hash-map (it sounds like that was what you were doing).