Comparator in Java

Comparator Interface is a very useful interface which is used to sort the objects on some predefined conditions. Usually when we want to sort Integer type ArrayList then we use Collections.sort(arrayListName). This will sort the list of integers in ascending order. But what if we want to sort Student objects based on the marks students … Read more

Selection Sorting in Java

In selection sorting each element is compared with all the following elements of the array. If the element is greater than any following element then swapping is done. After the first cycle we obtain the smallest element at the starting. Now in the second cycle, second element is compared with all following elements to obtain … Read more

Bubble Sorting in Java

Bubble sorting and Linear sorting are the easiest methods of sorting. Also they are the least optimized sorting algorithms. First we are going to look at bubble sorting in java. In Bubble sort each element is compared with its next element, if the element is greater than the next element then they are swapped. This … Read more

Sorting in Java

Sorting is the process through which elements can be arranged in ascending or descending order. Sorting can be done on numbers, strings etc. In Java inbuilt functions are also available to directly sort the series. These inbuilt functions are provided by Collections framework in Java. Example :- Unsorted series = 24, 20, 100, 203, 1, … Read more