Heading

Wednesday, November 20, 2013

Sorting an Array in java

package collections;

import java.util.Arrays;

public class ArraySortExample {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int[] i={10,6,8,25,99,100};
        System.out.println("Before Sorting:");
        for(int j:i)
            System.out.print(j+" ");
        Arrays.sort(i);
        System.out.println("\n After Sorting:");
        for(int k=0;k<i.length;k++)
            System.out.print(i[k]+" ");
    }

}

O/P:
Before Sorting:
10 6 8 25 99 100
 After Sorting:
6 8 10 25 99 100

No comments:

Post a Comment