java - 如何在 Android 中创建 Hashmap

标签 java android hashmap

我想创建 hashmap。这怎么可能 我想要如下所示的这种类型的 hashmap

{Question=how are you, friend=mack}
{Question=how are you, friend=jack}
{Question=hello, friend=mack}
{Question=hello, friend=jack}

它如何从下面的代码中得到这种类型的 map

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 是数组列表

最佳答案

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

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

关于java - 如何在 Android 中创建 Hashmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9595792/

相关文章:

java - hibernate 生成的表,但不显示在 mysql 数据库中

java - Android ListView : how to use fast scrolling and alphabetical ordering

java - 为什么dialog.show()导致我的应用程序崩溃?

java - try catch - 无法实例化 Activity ComponentInfo

java - 如何使用其他 HashMap 的对象在 HashMap 中定义 HashMap

java - 在控制台中,有没有办法阻止 java 在按 enter 时开始换行?

java - eclipse 开普勒 CDT “Symbol NULL could not be resolved”

android - 如何在android中创建数据库?

java - 如何添加另一个 Activity 作为登录屏幕android

android - 如何用逗号分隔数组列表值并放入hashmap