当键是对象时如何访问哈希映射键 [英] How To Access hash maps key when the key is an object

查看:24
本文介绍了当键是对象时如何访问哈希映射键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法弄清楚如何访问我的哈希图的值

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)

这篇关于当键是对象时如何访问哈希映射键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆