获取的ArrayList<的NameValuePair>值的名字 [英] Get ArrayList<NameValuePair> value by name

查看:545
本文介绍了获取的ArrayList<的NameValuePair>值的名字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是个正确的方式来获得的ArrayList<的NameValuePair>的名字

Is it a correct way to get ArrayList<NameValuePair> value by name ?

private String getValueByKey(ArrayList<NameValuePair> _list, String key) {
    for(NameValuePair nvPair : _list) {
        if(nvPair.getName().equals(key)) {
            return nvPair.getValue().toString();
        }
    }
    return null;
}

或者,是否有访问的快捷键的ArrayList&LT;的NameValuePair&GT; 值按名称

推荐答案

没有 - 你将它们存储为一个列表,它的目的不是要通过钥匙,您 - 它没有任何的概念关键的。

No - you're storing them as a list, which isn't designed to be accessed by "key" - it doesn't have any notion of a key.

这听起来像真的是你想要的东西就像一个地图&LT;字符串,字符串&GT; - 假设你只需要存储每个键的单一值

It sounds like really you want something like a Map<String, String> - assuming you only need to store a single value for each key.

如果你坚持用的ArrayList (和我的参数类型至少更改为列表如果不是可迭代因为那是你所需要的),那么你有什么是好的。

If you're stuck with the ArrayList (and I'd at least change the parameter type to List, if not Iterable given that that's all you need) then what you've got is fine.

这篇关于获取的ArrayList&LT;的NameValuePair&GT;值的名字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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