Comparator.comparing(…).thenComparing(…) find out which fields did not match

I am trying to compare two objects of same class and the goal is to compare them as well as identify which fields didn’t match. Example of my domain class @Builder(toBuilder=true) class Employee { …

How to write custom comparator in java?

I want to store key-value pairs in TreeMap and sort the entries based on the value of key as per the following logic: “type” (case insensitive) key should be at first. the key start with &…

LinkedList inside a LinkedList iteration in java

Im trying to iterate a Linked List inside of a linked list but I’m not sure how to proceed with it. I’m used to using a passed parameter for what will be iterated but when I’m iterating a linked list …

Why compareTo throws NPE using a comparator who doesn’t do that when user separatedly

I created a comparator that never throws NPE. However, when using it inside compareTo, it throws NPE. Why? public class Person implements Comparable { public static final Comparator&…

understanding comparator in Collections.max

Can somebody please explain what the following lines of code mean?. I had a hard time understanding the Comparator part.I tried googling but all of them were too complex for me to understand. Could …