sort a set in java code example
Example 1: java list to set
Set<Foo> foo = new HashSet<Foo>(myList);
Example 2: selection sort in java
public static void SelectionSort(int[] arr)
{
int small;
for (int i = 0; i <arr.length - 1; i++)
{
small = i;
for (int j = i + 1; j < arr.length; j++)
{
if (arr[j] < arr[small])
{
small = j;
int temp = arr[i];
arr[i] = arr[small];
arr[small] = temp;
}
}
}
}
Example 3: how to sort collection in java
import java.util.*;
ArrayList<String> al = new ArrayList<String>();
al.add("teach");
al.add("sleep");
al.add("geek");
Collections.sort(al);
System.out.println(al);
or