Learn Java and Programming through articles, code examples, and tutorials for developers of all levels.
Preparing for Java Interview?
My books Grokking the Java Interview and Grokking the Spring Boot Interview can help
Difference between Proxy and Decorator Pattern in Java
Unix command to find IP address from hostname - Linux example
How to find Files with Matching String in Linux? grep -l command Example
6 Essential Data Structures Java Programmer should Learn
How to Find Missing Number in a Sorted Array in Java [Solved]
13 Java Serialization Interview Questions with Answers for 3 to 5 Years Experienced
6 Best Free AZ-900 Azure Fundamentals Courses for Beginners to Learn Online in 2024
Top 70 Java Interview Questions for Junior Developers [1 to 2 Years Experienced]
Top 5 Free JavaScript Books for Beginners - Download PDF or Read Online
Difference between Set, List and Map in Java - Interview question
Difference between Heap and Stack Memory in Java? [Explained]
Top 80 Core Java Interview Questions with Answers
10 Free Java Programing Books for beginners - download, pdf and HTML
How does Hello world program in Java works? Example and Explanation
How to Create, Start, and Stop a New Thread in Java? [Example Tutorial]
How to use CountDownLatch in Java? Example
How to sort a List or Stream by Multiple Fields in Java? Comparator comparing() + thenComparing Example
One of the common requirements in Java is to compare objects by multiple fields. For example, if you have a list of CreditCard objects and you want to compare them by their provider and credit limit I mean, first compare them by their providers like VISA, Master, or American Express and if they are from the same provider then compare them by their credit limit, also known as breaking ties. Before Java 8 this wasn't easy because you have to write nested codes to compare multiple fields of an object as there was no easy way to chain multiple Comparators in Java, but things have changed a lot from Java 8.