Android NameValuePair:我可以在其中存储非字符串数据类型吗?

时间:2014-11-26 17:56:56

标签: java android apache basicnamevaluepair

documentation here我们可以看到它是org.apache.http.NameValuePair,因此查看原始documentation given here at apache.org,它有构造函数:

public NameValuePair(String name,
                     String value)

但我也想存储其他数据类型值,如boolean和int。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

来自NameValuePair

org.apache.http和其他已弃用的类已完全在API级23中删除。

您可以使用android.util.Pair,它使用泛型并允许您存储任何数据类型,例如:

// stores boolean values    
Pair<String, Boolean>> p1 = new Pair<>("key", false));

// stores int values
Pair<String, Integer>> p2 = new Pair<>("key", 1));