Since I\'m just starting with JAVA, I\'m curious what is the best option for implementing sorting in JAVA (for ArrayLists). Below I provide my PHP code.
public i
The simplest way to implement sorting in Java Collections is using the Collections#sort method.
It uses a modified merge sort algorithm to do the job.
It is important to say that it can only sort objects of a class that implements the Comparable interface, so you may need to take that into account. When you implement this interface you should know that it is best to think about the natural ordering of the object in question. e.g. Alphabetic order for Strings, if you need to sort it in an unnatural way on a specific context, do not use this interface.
For that it's best if you define a Comparator when you invoke the method.