If you are asking about a structure type you would use then I would suggest to go with a Map of Strings (names of words) to List of Integers (indexes of these words).
The class below shows how I implemented a Map storing Lists.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* Class of a map which allows to have a list of items under a single key.
* @author Konrad Borowiecki
*
* @param <T1> type of the key.
* @param <T2> type of objects the value list will store.
*/
public class ListHashMap<T1, T2> extends HashMap<T1, List<T2>>
{
private static final long serialVersionUID = -3157711948165169766L;
public ListHashMap()
{
}
public void addItem(T1 key, T2 item)
{
if(containsKey(key))
{
List<T2> tml = get(key);
tml.add(item);
}
else
{
List<T2> items = new ArrayList<T2>();
items.add(item);
put(key, items);
}
}
public void removeItem(T1 key, T2 item)
{
List<T2> items = get(key);
items.remove(item);
}
public void removeItem(T2 item)
{
Set<java.util.Map.Entry<T1, List<T2>>> set = entrySet();
Iterator<java.util.Map.Entry<T1, List<T2>>> it = set.iterator();
while(it.hasNext())
{
java.util.Map.Entry<T1, List<T2>> me = it.next();
if(me.getValue().contains(item))
{
me.getValue().remove(item);
if(me.getValue().isEmpty())
it.remove();
break;
}
}
}
}
In your case you would have a mapping of words to list of indexes so, you would call the class like this:
ListHashMap<String,Integer> wordToIndexesMap = new ListHashMap<String,Integer>();
Enjoy, Boro.