import static java.lang.System.out;
import java.util.Arrays;
class SortArray2
{
static public void main(String...alt)
{
String[] s={"zoo","apple","cat","banana","lock"};
out.println("Before Sorting : ");
for(String x:s)
out.print(x+" ");
out.println("\n\nAfter Sorting : ");
Arrays.sort(s); // public static void sort(java.lang.Object[])
for(String x:s)
out.print(x+" ");
}
}
import java.util.Arrays;
class SortArray2
{
static public void main(String...alt)
{
String[] s={"zoo","apple","cat","banana","lock"};
out.println("Before Sorting : ");
for(String x:s)
out.print(x+" ");
out.println("\n\nAfter Sorting : ");
Arrays.sort(s); // public static void sort(java.lang.Object[])
for(String x:s)
out.print(x+" ");
}
}
0 Comment to "Java Program to sort Object/String class elements with default natural sorting order."
Post a Comment