How to arrange my array in alphabetical order?
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
publicclass TaskSorter
{
//ByTitle bt;
//ByDueDate dd;
String[] test ={"Rat","Ox","Tiger","Rabbit","Dragon","Snake",
"Horse","Sheep","Monkey","Rooster","Dog","Boar"};
public TaskSorter()
{
}
publicstaticvoid main(String[] args)
{
(new TaskSorter()).title();
//(new TaskSorter()).duedate();
}
privatevoid 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[i]);
}
}
publicstaticclass ByTitleimplements Comparator
{
publicint compare(Object o1, Object o2)
{
return o1.toString().length() - o2.toString().length();
}
}
}

