title: Sorting an array with multiple elements
body: <p>I am making a to-do list in java for a class project. In the jList i display a date and a string that represent a date and what needs to be done on that day. I would also like to be able to sort these events by the dates on them, so the tasks that are due sooner appear first. I know how to sort a list of dates using bubble sort, but I do not know how to apply this to my list because each item contains a date AND a string. This is the code I have so far. Does anyone know how I will be able to sort the dates in order and keep the strings attached to their dates. Thanks. </p>
  
  <pre><code>public class ToDoListManager {
  
      final int maxitems = 20;
      int items = 0;
      String[] toDoList = new String[20];
      Date[] Dates = new Date[20];
  
      String addItem(String toDo, Date date) {
          if (items == maxitems) {
              return ("No more Space");
          } else if (toDo.equalsIgnoreCase("") || (toDo == null) || (date == null)) {
              return ("All fields required");
          } else if (items &lt; maxitems) {
              Dates[items] = date;
              SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd");
              toDoList[items] = "On " + dt1.format(date) + " " + toDo;
              items = items + 1;
              return (toDo + " Was Added to the List");
          }
          return null;
      }
  
      void Order(Date[] dates) {
          Date temp;
          boolean fixed = false;
          while (fixed == false) {
              fixed = true;
              for (int i = 0; i &lt; dates.length - 1; i++) {
                  if (dates[i].before(dates[i + 1])) {
                      temp = dates[i + 1];
                      dates[i + 1] = dates[i];
                      dates[i] = temp;
                      fixed = false;
                  }
              }
  
          }
          System.out.println(dates);
  
      }
  
      String[] getItems() {
          String[] displayList = new String[items];
          for (int i = 0; i &lt; items; i++) {
              displayList[i] = toDoList[i];
  
          }
  
          return displayList;
  
      }
  }
  </code></pre>