In the database, I have data in this format:

The requirement is to represent the data in the excel in this format: The country name forms the tab name.

I was thinking to put every DB row in a object.. To achieve in the format, I need to iterate over the country list, then in each country list (e.g US), pick the list of States (NY, NY) and then within that loop iterate over the each state (e.g NY), so that you get New York and Alaby. Repeat this for other states & then come out of the loop & then iterate over other countries in the same fashion.
But the difficulty I am facing here is, how do I represent that data in Java which will allow me to iterate in the required format? So that when I Iterate over US, it gives me NY and NJ and when I iterate over NJ, it gives me cities within it. I am struck. Please advice some pointers to get me going
Use a
Map<String, Map<String, List<String>>>.Be sure to properly initialize the data before inserting your data. For example, here I insert “New York City” as an American city in the NY state:
To get the list of cities in (US, NY), you have to do :
… which given our initialization process should return a list containing one item.