如何从Java中的HashMap提取值?

时间:2018-10-04 13:43:57

标签: java

假设我们有一个如下所示的HashMap:

{tones=
  [
    {score=0.534486, tone_id=joy, tone_name=Joy},
    {score=0.619262, tone_id=sadness, tone_name=Sadness},
    {score=0.829266, tone_id=analytical, tone_name=Analytical}
  ]
}

并且我们仅从中提取“分数”值和“ tone_name”值,我们该怎么做?

1 个答案:

答案 0 :(得分:1)

尝试一下:

Iterator it = tones.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry)it.next();
        if("score".equalsIgnoreCase(pair.getValue()) || "tone_name".equalsIgnoreCase(pair.getValue())){
            iter.remove();
        }
    }