title: How would I go about finding the closest date to a specified date? (Java)
body: <p>I was hoping to know how I would type up a method to give me the closest date to a specified date. What I mean is something along the following:</p>
  
  <pre class="lang-java prettyprint-override"><code>public Date getNearestDate(List&lt;Date&gt; dates, Date currentDate) {
      return closestDate  // The date that is the closest to the currentDate;
  }
  </code></pre>
  
  <p>I have found similar questions, but only one had a good answer and the code kept giving me NullPointerExceptions ...
  Can anyone help me?</p>