title: What is the best way to get min and max value from a list of Comparables that main contain null values?
body: <p>I am thinking about something like this:</p>
  
  <pre><code>public static &lt;T extends Comparable&lt;T&gt;&gt; T minOf(T...ts){        
      SortedSet&lt;T&gt; set = new TreeSet&lt;T&gt;(Arrays.asList(ts));
      return set.first();
  }
  
  public static &lt;T extends Comparable&lt;T&gt;&gt; T maxOf(T...ts){
      SortedSet&lt;T&gt; set = new TreeSet&lt;T&gt;(Arrays.asList(ts));
      return set.last();
  }
  </code></pre>
  
  <p>But is not null safe, which is something I want too.</p>
  
  <p>Do you know a better way to solve this problem?</p>
  
  <p>EDIT:</p>
  
  <p>After the comments I have also tried min():</p>
  
  <pre><code>public static &lt;T extends Comparable&lt;T&gt;&gt; T minOf(T...ts){        
      return Collections.min(Arrays.asList(ts), new Comparator&lt;T&gt;(){
  
          public int compare(T o1, T o2) {
              if(o1!=null &amp;&amp; o2!=null){
                  return o1.compareTo(o2);
              }else if(o1!=null){
                  return 1;
              }else{
                  return -1;  
              }
          }});
  }
  </code></pre>
  
  <p>What do you think of that?</p>