009-java中常用的單個鍵值對


1、Java 6提供AbstractMap.SimpleEntry<K,V>和AbstractMap.SimpleImmutableEntry<K,V> 

Map.Entry<String,Integer> entry1 = new AbstractMap.SimpleEntry<String, Integer>("key", 9527);

2、Apache commons-collections的KeyValue 

Map.Entry<String,Integer> entry3 = new DefaultMapEntry("key", 9527)
KeyValue<String,Integer> kv = new DefaultKeyValue("rkey", 9527);

3、Guava的Maps.immutableEntry 

Map.Entry<String,Integer> entry2 = Maps.immutableEntry("key", 9527);

4、Apache commons-lang3的Pair 

Map.Entry<String,Integer> entry4 =new ImmutablePair<String,Integer>("key", 9527);

5、Apache HttpClient的NameValuePair 

NameValuePair nv = new BasicNameValuePair("key", "9527");

可以擴展Map.Entry或者封裝Class。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM