I have a program which has the user inputs a list of names. I have a switch case going to a function which I would like to have the names print off in alphabetical order.
You can use Arrays.sort() method. Here's the example,
import java.util.Arrays;
public class Test
{
public static void main(String[] args)
{
String arrString[] = { "peter", "taylor", "brooke", "frederick", "cameron" };
orderedGuests(arrString);
}
public static void orderedGuests(String[] hotel)
{
Arrays.sort(hotel);
System.out.println(Arrays.toString(hotel));
}
}
Output
[brooke, cameron, frederick, peter, taylor]