Java Compare

Java Sorting

Sorting a Stream by Multiple Fields in Java

Java 8 example to sort stream of objects by multiple fields using comparators and Comparator.thenComparing() method. This method returns a lexicographic-order comparator with another comparator. It gives the same effect as SQL group by clause.

Java Comparator Interface

Java Comparator interface used to sort a array or list of objects based on custom order. Custom ordering of elements is imposed by implementing Comparator.compare() method in the objects.

Java Comparable Interface

Java Comparable interface is part of Collection Framework. Learn the purpose of Comparable interface and use it in different scenarios. 1. Comparable Interface 1.1. Why Implement Comparable? In Java, if we want to sort a List of elements then we can Collections.sort() method. It sorts the list items according to …

Java String compareToIgnoreCase()

Java String compareToIgnoreCase() example compares two strings lexicographically ignoring case. Learn how it differs from equalsIgnoreCase().

Java String compareTo()

Java String compareTo() method example. Learn to compare two strings lexicographically. We can consider this string comparison dictionary based comparison.

Java String equalsIgnoreCase()

Java String.equalsIgnoreCase() compares the current string with the specified string in a case-insensitive manner. Learn with examples.

Java String.equals()

Learn to compare the content of two String objects in a case-sensitive manner using the String.equals() API. For case-insensitive comparison, we can use the equalsIgnoreCase() method. Never use ‘==’ operator for checking the strings equality. It verifies the object references, not the content, which is undesirable in most cases. 1. String.equals() API …

Java Comparator with Lambda

Learn to create a Comparator instance with lambda expressions, method references and chaining multiple comparators for complex comparisons.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.