title: Sorting a list of pojos in Java
body: <p>I would like to sort a list of Pojos based on the field (sortField) and order (sortOrder) parameters passed in.  I have this working (for 6 fields) - </p>
  
  <pre><code>switch (sortField) {
    case "field1" :
      if (sortOrder == "asc") {
        list.sort((lItem1, lItem2) -&gt; lItem1.getField1().compareTo(lItem2.getField1()));
      } else {
        list.sort((lItem1, lItem2) -&gt; lItem2.getField1().compareTo(lItem1.getField1()));
      }
    break; 
    case "field2" :
      if (sortOrder == "asc") {
        list.sort((lItem1, lItem2) -&gt; lItem1.getField2().compareTo(lItem2.getField2()));
      } else {
        list.sort((lItem1, lItem2) -&gt; lItem2.getField2().compareTo(lItem1.getField2()));
      }
    break;
    //...
  }
  </code></pre>
  
  <p>This works perfectly but feels a little bit clunky and I just wondered if anyone could point me to a (relatively simple!) tidier &amp; more graceful way to do it ?</p>