title: How to "group by" a list of objects by a class attribute in Java?
body: <p>I have a linked list with nodes, each node contains Flight objects
  which have several attributes (Origin city, Destination city, etc).</p>
  
  <p>I want to build a list, in a similar manner to SQL's group by; for each origin city all the flights and their origins</p>
  
  <p>I've tried storing cities in a list but I don't know how to initialise it, NetBeans says I can't and I don't know how to do it.</p>
  
  <p>This is what I've got so far, last part is a comment since I don't know how to properly implement it.</p>
  
  <pre><code>public void PrintList() {
      NodeFlight aux = start;
      List&lt;String&gt; Ciudades;
  
      while (aux != null) {
          //add to the list cities if current.getcity isn't in the list already??
          //current=next;
      }
  
      //loop for each element in the city list
      //current=start;
  
      //loop if current equals to the first element of the list?
      //print each element which origin city is equals to the city list current index
      //close first loop
  
      //next city? i++? whatever
      //close bigger loop?
  }
  </code></pre>
  
  <p>The format I'm looking for is something like:</p>
  
  <pre><code>"Origin city"
      1 - "Flight1"
      2 - "Flight2"
      ...
      N - "FlightN"
  "Origin city"
      1.........
  </code></pre>
  
  <p>And so on.</p>