title: Comparator alternative , if 2 attributes have same value
body: <p>Currently I am working on a scenario in which I have to find minimum Timestamp and have to print corresponding amount and second scenario is suppose If Timestamp of 2 data is same then I have to print timestamp and sum of both the amount. I am not able to achieve the second scenario through comparator. If you people have some solution or any alternative please let me know.</p>
  <p>Code:</p>
  <pre><code>import java.util.Arrays;
  import java.util.Comparator;
  import java.util.List;
   
  class Student {
      private String timestamp;
      private int amount;
   
      public Student(String timestamp, int amount) {
          this.timestamp = timestamp;
          this.amount = amount;
      }
   
      public String getTimestamp() {
          return timestamp;
      }
   
      public int getAmount() {
          return amount;
      }
   
      @Override
      public String toString() {
          return &quot;Student{&quot; +
                  &quot;timestamp='&quot; + timestamp + '\'' +
                  &quot;, amount=&quot; + amount +
                  '}';
      }
  }
   
  public class Main
  {
      public static void main(String[] args)
      {
          List&lt;Student&gt; students = Arrays.asList(
                  new Student(&quot;2022-06-06 14:19:37.000&quot;, 25),
                  new Student(&quot;2022-06-06 14:19:37.000&quot;, 15),
          );
   
          
   
          Comparator&lt;Student&gt; timestampComparator = Comparator
        .comparing(Student::getTimestamp);
      Student earliestDate = students.stream()
        .min(timestampComparator)
        .get();
      }
  }
  
  </code></pre>
  <p>The expected output-
  2022-06-06 14:19:37.000, 40</p>
  <p>Output that I am getting-
  2022-06-06 14:19:37.000, 25</p>