【问题标题】:How to Create Hashmap in android如何在android中创建Hashmap
【发布时间】:2012-03-07 04:20:58
【问题描述】:

我想创建 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 是数组列表

【问题讨论】:

  • 我不明白这个问题。您想知道如何创建地图列表吗?
  • 是的,我再次编辑了我的问题
  • 你有什么问题?如果你不告诉我们出了什么问题,对我们没有好处。

标签: java android hashmap


【解决方案1】:

如果我理解您的问题,您想知道如何声明地图列表。你可以这样做:

List<Map<String, String>> mylist = new ArrayList<Map<String, String>>();
List<Map<String, String>> mylist1 = new ArrayList<Map<String, String>>(); 

【讨论】:

    【解决方案2】:

    Android 有 HaspMap 数据结构。请看下面的代码并了解一下:

    ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    list.put("Question=hello", "friend=jack");
    

    【讨论】:

      猜你喜欢
      • 2018-11-30
      • 2011-05-06
      • 2016-03-28
      • 1970-01-01
      • 2012-03-01
      • 2023-04-11
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      相关资源
      最近更新 更多