Sunday, February 12, 2017

Java Program to sort Object/String class elements with default natural sorting order.

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+" ");
}
}

Share this

0 Comment to "Java Program to sort Object/String class elements with default natural sorting order."

Post a Comment