import java.util.ArrayList;

// SELECTION SORT

public class Sort2
{

private ArrayList names;

public Sort2()
{ names = new ArrayList();

names.add("Charles"); names.add("Noza"); names.add("Steven"); names.add("Evan"); names.add("Itai");names.add("Kaitlin");
names.add("Marcus"); names.add("Aaron"); names.add("Zizhong"); names.add("AndrewM"); names.add("Nick"); names.add("Khushi");
names.add("Sebastian"); names.add("Siddharth"); names.add("Matt"); names.add("Raghav"); names.add("Luke"); names.add("Bella");
names.add("Asadullah"); names.add("AndrewS"); names.add("Antoni"); names.add("Harsh");
}

public void doSort2()
{
int position = 0; // put the next name alphabetically into position
int k, j, result, firstSoFarPosition = 0;
String firstSoFar, name;
for (j = 0; j < names.size(); j++)
{
    firstSoFar = names.get(position);
    firstSoFarPosition = position;
    for (k = position; k < names.size(); k++)
    {
        name = names.get(k);
        result = name.compareTo(firstSoFar);
        // compareTo returns a negative number if 'name' comes before 'firstSoFar'
        // compareTo returns a positive number if 'name' comes after 'firstSoFar'
        // compareTo returns 0 if they are the same
        if (result < 0)
        { firstSoFar = name;
            firstSoFarPosition = k;
        }
    } // end of inner loop
    System.out.println("firstSoFar: " + firstSoFar);
    System.out.println("firstSoFarPosition: " + firstSoFarPosition);
    System.out.println(names);
    // swap with the name at 'position'
    String temp;
    temp = firstSoFar;
    names.set(firstSoFarPosition, names.get(position));
    names.set(position, firstSoFar);
    position++;
} // end of outer loop
}

public static void main(String[] args)
{     Sort2 s = new Sort2();
    s.doSort2();

}