

Program: Implement selection sort in java.
The selection sort is a combination of searching and sorting. During each pass, the unsorted element with the smallest
(or largest) value is moved to its proper position in the array. The number of times the sort passes through the array is one less
than the number of items in the array. In the selection sort, the inner loop finds the next smallest (or largest) value and the outer
loop places that value into its proper location.
Selection sort is not difficult to analyze compared to other sorting algorithms since none of the loops depend on the data
in the array. Selecting the lowest element requires scanning all n elements (this takesn − 1 comparisons) and then swapping it into the
first position. Finding the next lowest element requires scanning the remaining n − 1 elements and so on,
for (n − 1) + (n − 2) + ... + 2 + 1 = n(n − 1) / 2 ∈ Θ(n2) comparisons. Each of these scans requires one swap for n − 1 elements.
package com.java2novice.algos;
public class MySelectionSort {
public static int[] doSelectionSort(int[] arr){
for (int i = 0; i < arr.length  1; i++)
{
int index = i;
for (int j = i + 1; j < arr.length; j++)
if (arr[j] < arr[index])
index = j;
int smallerNumber = arr[index];
arr[index] = arr[i];
arr[i] = smallerNumber;
}
return arr;
}
public static void main(String a[]){
int[] arr1 = {10,34,2,56,7,67,88,42};
int[] arr2 = doSelectionSort(arr1);
for(int i:arr2){
System.out.print(i);
System.out.print(", ");
}
}
}


Output: 
2, 7, 10, 34, 42, 56, 67, 88,





Java Sorting Algorithms Examples
 Implement bubble sort in java.
 Implement selection sort in java.
 Implement insertion sort in java.
 Implement quick sort in java.
 Implement merge sort in java.



What is adapter class?
An adapter class provides the default implementation of all methods in an event listener interface. Adapter classes are very useful when you want to process only few of the events that are handled by a particular event listener interface. You can define a new class by extending one of the adapter classes and implement only those events relevant to you.
You can never get enough of what you don’t really need.
 Eric Hoffer
