title: Iterate and combine two sorted arraylists of different objects
body: <p>My situation is like this: I have two arraylists with different types of objects. Each object has a field name and a field date
  ArrayList events, ArrayList things . I sorted the arraylists by name, and if the name is the same, sorted them by date.</p>
  
  <p>Lets say that <strong>ArrayList1</strong> has the following objects : <strong>event1 01.12, event1 05.12, event2 04.03, event3 05.05</strong></p>
  
  <p>And <strong>ArrayList2</strong> has: <strong>event0 02.01, event2 05.10</strong></p>
  
  <p>Now I want to make a TableRow containing a textview with an Event name and another textview with the dates for it.
  So my table layout will be like this:</p>
  
  <pre><code>Event0    02.11(from2)
  Event1    01.12(from1), 05.12(from1)
  Event2    02.01(from2), 04.03(from1)
  Event3    05.10(from1)
  </code></pre>
  
  <p>How can I iterate through the 2 arraylists and get each unique event and all the dates for it to show in a TableRow?</p>
  
  <p>I sort them like this</p>
  
  <pre><code>Collections.sort(alist, new Comparator&lt;Object1&gt;() {
                  @Override
                  public int compare(Object1 a1, Object1 a2) {
                      SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
                      Date date1;
                      Date date2;
                      if(a1.name.equals(a2.name)) {
                          try {
                              date1 = format.parse(a1.date);
                              date2 = format.parse(a2.date);
                          } catch (ParseException e) {
                              throw new IllegalArgumentException("Could not parse date!", e);
                          }
                          return date1.compareTo(date2);
                      }
  
                      else
                          return a1.name.compareTo(a2.name) ;
                  }
  
              });
  </code></pre>