Insertion sort algorithm simple explanation with example

Insertion sort in java. Inserttion sort algorithm is explained here, with an example on sorting an array. The main idea of insertion sort is to repeatedly find the next  smallest number and move it to the starting position, if the sorting is  to be in ascending (increasing) order. Read other sorting algorithms like insertion sort and bubble sort along with this which helps you to understand sorting algorithms in clear.


Take an array consist of four numbers {72,18,8,90}

program to sort the string in alphabetical order in java

Simple java program to sort and  print the names in alphabetical order using compareTO(). To arrange the given strings in alphabetical order, first we need to compare each consecutive string and swap them according to the order. In this example, built-in function compareTo()  is used to compare two string.
Example of compareTo: