0

I have written a nested hashmap like this...

    HashMap<String, String> choice_map = new HashMap<String, String> ();

    choice_map.put("4","<?php ?>");
    choice_map.put("2","<? ?>");
    choice_map.put("1","<? >");
    choice_map.put("3","< ?>");

    HashMap<String, String> que_id_map = new HashMap<String, String> ();

    que_id_map.put("1",null);

    HashMap<String, String> que_type_map = new HashMap<String, String> ();

    que_type_map.put("Objective",null);

    HashMap<String, String> que_map = new HashMap<String, String> ();

    que_map.put("What is Short Tag in PHP?",null);

    HashMap<String, HashMap<String, String>> main_choice_map = new HashMap<String, HashMap<String, String>>();


    main_choice_map.put("question",que_map);
    main_choice_map.put("question_type_id",que_id_map);
    main_choice_map.put("question_type",que_type_map);
    main_choice_map.put("choices",choice_map);

   HashMap<String, HashMap<String, HashMap<String, String>>> questions_with_choices = new HashMap<String, HashMap<String, HashMap<String, String>>> ();

   questions_with_choices.put("2",main_choice_map);

The output of the above hashmap (questions_with_choices) is like this:

{2={question_type_id={1=null}, question_type={Objective=null}, choices={3=< ?>, 2=<? ?>, 1=<? >, 4=<?php ?>}, question={What is Short Tag in PHP?=null}}}

How to iterate through this hashmap in jsp or jstl?

Please help me..

kamal
  • 1

1 Answers1

0
<%
Iterator it = mp.entrySet().iterator();
while (it.hasNext()) {
    Map.Entry pairs = (Map.Entry)it.next();
%>
    <h1><%=pairs.getKey()%> = <%=pairs.getValue()%></h1>
<%
    it.remove(); // avoids a ConcurrentModificationException
}
%>
kwikness
  • 1,425
  • 4
  • 21
  • 37
  • thanks for ur answer.. kindly give the full code for my hashmap... i will accept your answer – kamal Sep 21 '14 at 08:28