4

i want to create hashmap.how its possible i want this type hashmap as below

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

how its get this type of map from below code

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 and mylist1 is arraylist

user1153176
  • 1,006
  • 5
  • 15
  • 21

2 Answers2

1

If I understand your question, you want to know how to declare a list of maps. You can do it like this:

List<Map<String, String>> mylist = new ArrayList<Map<String, String>>();
List<Map<String, String>> mylist1 = new ArrayList<Map<String, String>>(); 
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
1

Android has HaspMap datastructre. See the below code and get idea:

ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
list.put("Question=hello", "friend=jack");
Awais Tariq
  • 7,724
  • 5
  • 31
  • 54