如何访问哈希映射键时,最关键的是一个对象 [英] How To Access hash maps key when the key is an object

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

问题描述

我似乎无法弄清楚如何访问我的HashMap的值

I cannot seem to figure out how to access the values of my hashmap

什么我基本上试图做的是创建一个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?

所以,我想是这样散{键:值1,值2,值3,[数字1,数字]}

和能够访问它像(伪code :) hash.get(3)获得(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));

    }

}

关键字句的ArrayList

这是我的 System.out.print(对外连结)的输出;

{[教育,新闻,互联网] = [0,3],[电源,新闻] = [1,4],[电脑,网络,设备,iPod的] = [2] [大学教育] = [5]}

我将如何去获得说眼前这个: [教育,新闻,互联网] = [0,3]

How would I go about getting say just this: [education, news, internet]=[0, 3]

我曾尝试:

outlinks.get(xfile.getKeyPhrases(I))

xfile.getKeyPhrases(0)将例如返回 [教育,新闻,互联网]

推荐答案

您可以拿到钥匙集(的 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天全站免登陆