[英]How to Create Hashmap in android
我想創建hashmap.how它可能我希望這種類型的hashmap如下所示
{Question=how are you, friend=mack}
{Question=how are you, friend=jack}
{Question=hello, friend=mack}
{Question=hello, friend=jack}
它如何從下面的代碼中獲取這種類型的地圖
map_friend = webservice.getFrend(); //{0=Mack, 1=jack}
map_QUE = webservice.getQuestion();//{0=How are you, 1=hello}
int RQSize = map_QUE.size();
int Isize = map_ITEM.size();
for (i = 0; i < RQSize; i++)
{
rate_map = new HashMap<String, String>();
final String val = map_QUE.get(i);
rate_map.put("Question", val);
mylist.add(rate_map);
for (j = 0; j < Isize; j++)
{
rate_map1 = new HashMap<String, String>();
final String val1 = map_friend.get(j);
rate_map1.put("friend", val1);
mylist1.add(rate_map1);
}
}
mylist和mylist1是arraylist
如果我理解您的問題,您想知道如何聲明地圖列表。 你可以這樣做:
List<Map<String, String>> mylist = new ArrayList<Map<String, String>>();
List<Map<String, String>> mylist1 = new ArrayList<Map<String, String>>();
Android有HaspMap數據結構。 請參閱以下代碼並了解相關信息:
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
list.put("Question=hello", "friend=jack");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.