Sorting an array is a common task encountered in a lot of domains/applications. It is so common that Java provides a built-in solution for sorting arrays of primitives and objects using a comparator. This solution works very well and is the preferable way to go in most of the cases. Let's take a look at the different solutions in the next section.