title: creating a map of an HTML table with jsoup, which is the best data structure?
body: <p>this is a problem that I already know how to solve, but since I wanna learn the best way to do it, I'm gonna ask here. I need to find the best data structure to hold elements of an HTML table that I loaded from an HTML page.</p>
  
  <p>The columns of the table are days of the week, and the lines are hours of each day. The elements of the table are organized by groups of lines, that is, a  tag that contains some  tags. Each  is one line, and each element inside the , that is, the , are lines. </p>
  
  <p>So, given this HTML structure, I need to iterate first by the lines, and then collect the elements of each column. Since, in my app, I wanna display only the day the person want, the data structure that I tought of was:</p>
  
  <pre><code>  Map&lt;String, Map&lt;String, String&gt;&gt; table = new HashMap&lt;String, Map&lt;String, String&gt;&gt;();
  </code></pre>
  
  <p>That is, each day is a key of the Map table, and each key points to another map, which is the map of hours of such day, that were in the table, and its values. So, for each day, there is an hour. This is the inverse of the table: for each hour, there was a day, given the linear way I had to scan the HTML document. </p>
  
  <p>Another approach would be to iterate through the columns first (the 's), but it's not the best way because I'd have to know in which line () they were. For me, it's better to iterate as the first way I did.</p>
  
  <p>So, the problem is that I need to create a Map for each day of the week, before the loop that will iterate through every hour (and will have another loop inside, that for each hour, will iterate through the days). This gave the following code:</p>
  
  <pre><code>Map&lt;String, String&gt; monday = new HashMap&lt;String, String&gt;();
    Map&lt;String, String&gt; thursday = new HashMap&lt;String, String&gt;();
    Map&lt;String, String&gt; wednesday = new HashMap&lt;String, String&gt;();
    Map&lt;String, String&gt; tuesday = new HashMap&lt;String, String&gt;();
    Map&lt;String, String&gt; friday = new HashMap&lt;String, String&gt;();
    Map&lt;String, String&gt; saturday = new HashMap&lt;String, String&gt;(); 
  </code></pre>
  
  <p>I look into code and think it's a mess, so I started thinking which would be a better way to structure and iterate through the objects of a table using Jsoup.</p>