Join Two List In Java & Remove Duplicates

Join Two List In Java & Remove Duplicates explains about how to merge two lists into a single list and removing duplicate entries using java api.

We have some situation where we need to join two or more Lists (ArrayList, LinkedList etc) into a single List.

There are lot of different ways, we can do this

Sort ArrayList Of Object

Sort ArrayList Of Object Example describes about How to sort an ArrayList of objects.

How to Sort An ArrayList Of Objects Using Comparator Interface

The best way to sort an ArrayList of Objects is using Collections.sort() method of Collections utility class.

But if you need to sort according to a particular field / column / property, then we can use Comparator interface and override compare method of Comparator interface.

Consider an ArrayList consists with lot of student objects, where student object have 2 properties like firstName & lastName. And you need to sort according to the firstName, then you can use comparator interface for sorting the ArrayList

int compare(T o1, T o2) Compares its two arguments for order.