Hi,
I'm having some trouble trying to organize my String array contents into alphabetical order.
like something like this:
Boar
Dog
Dragon
Horse
Here's my code so far:
-but the way I have arranged it so far, is only by the number of characters in the string
public class TaskSorter
{
//ByTitle bt;
//ByDueDate dd;
String[] test = {"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",
"Horse", "Sheep", "Monkey", "Rooster", "Dog", "Boar" };
public TaskSorter()
{
}
public static void main(String[] args)
{
(new TaskSorter()).title();
//(new TaskSorter()).duedate();
}
private void title()
{
ByTitle bt = new ByTitle ();
Arrays.sort(test, bt);
System.out.println("- Title Order -------------");
for (int i = 0; i < test.length; i++)
{
System.out.println(test);
}
}
public static class ByTitle implements Comparator
{
public int compare(Object o1, Object o2)
{
return o1.toString().length() - o2.toString().length();
}
}
}