Java Arrays sort String array

Description

Java Arrays sort String array

import java.util.*;

public class Main {
    public static void main(String[] arguments) {
        String names[] = { "A", "CSS", "R", "C++",
            "T-SQL", "HTML", "Java", "Pascal", "Javascript" };
        System.out.println("The original order:");
        for (int i = 0; i < names.length; i++) {
            System.out.println(i + ": " + names[i]);
        }//  w ww  .j a  v  a  2s .c  o  m
        System.out.println();
        Arrays.sort(names);
        System.out.println("The new order:");
        for (int i = 0; i < names.length; i++) {
            System.out.println(i + ": " + names[i]);
        }
        System.out.println();
    }
}



PreviousNext

Related