当键是对象时如何访问哈希映射键
我似乎无法弄清楚如何访问我的哈希图的值
I cannot seem to figure out how to access the values of my hashmap
我基本上想要做的是创建一个带有数组的哈希图作为 json 样式等值之一.. 如果这有意义吗?
What I am basically trying to do is create a hashmap with an array as one of the values like json style.. If that makes sense?
所以我想要类似 hash{key: value1, value2, value3, [number1,number2]}
并且能够像(伪代码:)一样访问它hash.get(3).get(1)
and be able to access it like (pseudocode:) hash.get(3).get(1)
public class WebSearch {
readFile.ReadFile xfile = new readFile.ReadFile("inputgraph.txt");
HashMap webSearchHash = new HashMap();
ArrayList belongsTo = new ArrayList();
ArrayList keyphrase = new ArrayList();
public WebSearch() {
}
public void createGraph()
{
HashMap <Object, ArrayList<Integer> > outlinks = new HashMap <Object, ArrayList<Integer>>();
for (int i = 0; i < xfile.getNumberOfWebpages(); i++ )
{
keyphrase.add(i,xfile.getKeyPhrases(i));
outlinks.put(keyphrase.get(i), xfile.getOutLinks(i));
}
}
keyphrases
是一个 ArrayList
这是我的System.out.print(outlinks);
{[education, news, internet]=[0, 3], [power, news]=[1, 4], [computer, internet, device, ipod]=[2], [university,教育]=[5]}
我该怎么说:[education, news, internet]=[0, 3]
我已经尝试过:
outlinks.get(xfile.getKeyPhrases(i))
xfile.getKeyPhrases(0)
例如返回 [education, news, internet]
您可以获取密钥集 (Map.keySet()) 首先是地图;outlinks.keySet()
You can get the key set (Map.keySet()) of the map first; outlinks.keySet()
然后您可以在地图上使用这些键来获取您的条目(键的值)
Then you can use these keys on your map to get your entries (values of the keys)