Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9108689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:51:58+00:00 2026-06-17T02:51:58+00:00

I have a Hashmap object allList in the form with type HashMap<String,ArrayList<Item>> . I

  • 0

I have a Hashmap object allList in the form with type HashMap<String,ArrayList<Item>>. I want to display it my JSP page as jquery accordion. Below is the code I have tried.

<script type="text/javascript">
$(function() {
    $( "#accordion" ).accordion({
        heightStyle: "fill",
        collapsible: true
     });
});

</script>

<div id="accordion">
       <c:forEach items="${allList}" var="myLs">
    <h3>${myLs.key}</h3>
    <div>${myLs.value}</div> // This is giving me toString of Item.
</c:forEach>
</div>

I am able to display hashmap’s keys as header. But I am unable to figure out how to display the corresponding arraylist object as ordered list. Please help me out.

public class Item implements java.io.Serializable, Comparable<Object> {
    private Long id;
    private String itemName;
    private Double unitCost;
    private String status;
    private int quantity;
    public Item() {
    }
        //getters and setters
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Item)) {
            return false;
        }
        final Item item = (Item) o;
        if (getItemName() != null && item.getItemName() == null)
            return false;
        if (getItemName() == null && item.getItemName() != null)
            return false;
        if (!getItemName().equals(item.getItemName()))
            return false;
        return true;
    }
    public int hashCode() {
            return getItemName().hashCode();
    }

    public String toString() {
       return "Item - Id: "+getId+", Name : "+getItemName;
    }
    public int compareTo(Object o) {
       if (o instanceof Item) {
           return getItemName().compareTo(((Item) o).getItemName());
       }
       return 0;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:51:59+00:00Added an answer on June 17, 2026 at 2:51 am

    You would use a second forEach loop:

    <div id="accordion">
        <c:forEach items="${allList}" var="myLs">
            <h3>${myLs.key}</h3>
            <div>
                <c:forEach var="item" items="${myLs.value}">
                    ${item.foo}, ${item.bar}  <br/>
                </c:forEach>
            </div>
        </c:forEach>
    </div>
    

    I think you’re confusing yourself by your bad naming choices. You should’ name a Map<String, ArrayList<Item>> allList, since it’s not a list, but a map. And you shouldn’t name a map entry myLs since it doesn’t mean anything. I would refactor the code to (assuming the key in the map, for example, represents the owner of the items)

    <div id="accordion">
        <c:forEach items="${itemsPerOwner}" var="itemsPerOwnerEntry">
            <h3>${itemsPerOwnerEntry.key}</h3>
            <div>
                <c:forEach var="item" items="${itemsPerOwnerEntry.value}">
                    ${item.foo}, ${item.bar}  <br/>
                </c:forEach>
            </div>
        </c:forEach>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HashMap object that I am getting on a JSP page. HashMap<Integer,Gift_product>
I have this object: Map<Long, Set<String>> resourcesByID = new HashMap<Long, Set<String>>(); and another: Set<String>
I have changed hashmap into collection,collection into object,now I need object into String.either this
I have HasMap object like this: HashMap<String,String> fileCounter = new HashMap<String,String>(); fileCounter.put(Total Files,15); fileCounter.put(Total
I have HashMap object contains a key x-y-z with corresponding value test-test1-test2 . Map<String,String>
I have a HashMap<String, Object> that looks like this when I call .toString() on
I have created a HashMap object which stores a String as key and corresponding
I have a List<HashMap<String,Object>> which represents a database where each list record is a
I have a map. Lets say: Map<String, Object> map = new HashMap<String, Object>(); Multiple
I have a HashMap having key as my own object and key as ArrayList

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.