Example usage for java.util Arrays sort

List of usage examples for java.util Arrays sort

Introduction

In this page you can find the example usage for java.util Arrays sort.

Prototype

public static void sort(Object[] a) 

Source Link

Document

Sorts the specified array of objects into ascending order, according to the Comparable natural ordering of its elements.

Usage

From source file:Main.java

public static void main(String[] args) {

    // initializing unsorted float array
    float fArr[] = { 13.2f, 1.2f, 0.7f, 1.2f, 4.5f };

    System.out.println(Arrays.toString(fArr));

    // sorting array
    Arrays.sort(fArr);

    System.out.println(Arrays.toString(fArr));
}

From source file:Main.java

public static void main(String[] args) {
    Integer[] points = new Integer[5];
    points[0] = 4;/* www  . j a v  a2s  .co  m*/
    points[1] = 3;
    points[2] = 0;
    points[3] = 4;
    points[4] = 4;

    Arrays.sort(points);
    System.out.println(Arrays.toString(points));

    Arrays.sort(points, Collections.reverseOrder());
    System.out.println(Arrays.toString(points));
}

From source file:Main.java

public static void main(String[] args) {
    String str = "Result";
    String str1 = "rEsLtu";

    char[] firstString = str.toLowerCase().toCharArray();
    char[] secondString = str1.toLowerCase().toCharArray();

    Arrays.sort(firstString);
    Arrays.sort(secondString);/*www.j av a  2  s .  c  o m*/

    if (Arrays.equals(firstString, secondString) == true) {
        System.out.println("same");
    } else {
        System.out.println("different");
    }
}

From source file:Main.java

public static void main(String[] args) {
    Employee[] staff = new Employee[3];

    staff[0] = new Employee("HTML", 35000);
    staff[1] = new Employee("Java", 75000);
    staff[2] = new Employee("CSS", 38000);

    Arrays.sort(staff);

    for (Employee e : staff) {
        System.out.println("name=" + e.getName() + ",salary=" + e.getSalary());
    }//from  w w  w .  j  ava  2s  .  co  m

}

From source file:Main.java

public static void main(String[] args) {
    int[] anArray = new int[1000];
    Random generator = new Random();
    for (int i = 0; i < 1000; i++) {
        anArray[i] = (generator.nextInt(1000) + 1);
    }//from w  w  w. j a v  a2 s . c o m
    Date before = new Date();
    Arrays.sort(anArray);
    Date after = new Date();
    System.out.println("milli seconds" + (after.getTime() - before.getTime()));
}

From source file:Main.java

public static void main(String[] args) {
    int numbers[] = { 3, 1, 8, 34, 1, 2, 13, 89, 5, 21, 55 };

    System.out.print("Before: ");
    for (int i = 0; i < numbers.length; i++) {
        int number = numbers[i];
        System.out.print(number + "; ");
    }//from www  .  j a v a 2s  .co  m
    Arrays.sort(numbers);

    System.out.print("After: ");
    for (int i = 0; i < numbers.length; i++) {
        int number = numbers[i];
        System.out.print(number + "; ");
    }
    float money[] = { 1.05f, 99.8f, 3f, 4.55f, 7.23f, 6.50f };
    Arrays.sort(money, 3, money.length);

    for (int i = 0; i < money.length; i++) {
        float v = money[i];
        System.out.print(v + "; ");
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    Random generator = new Random();

    for (int i = 0; i < 10; i++)
        data[i] = 10 + generator.nextInt(90);

    Arrays.sort(data);

    System.out.println(binarySearch(3));
}

From source file:MainClass.java

public static void main(String[] args) {
    File path = new File(".");
    String[] list;//from  w  ww  .j a v a2s .  com
    if (args.length == 0)
        list = path.list();
    else
        list = path.list(new DirFilter(args[0]));
    Arrays.sort(list);
    for (int i = 0; i < list.length; i++)
        System.out.println(list[i]);
}

From source file:StringSorting.java

public static void main(String[] args) {
    String[] sa = new String[] { "d", "e", "a", "c", "g" };

    System.out.println("Before sorting: " + Arrays.asList(sa));
    Arrays.sort(sa);
    System.out.println("After sorting: " + Arrays.asList(sa));
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    String[] words = { "", "e", "a", "c" };
    Writer w = new BufferedWriter(new OutputStreamWriter(System.out, "Cp850"));
    for (int i = 0; i < 4; i++) {
        w.write(words[i] + " ");
    }//from   w  w  w . j a  va 2 s. co m
    Arrays.sort(words);
    for (int i = 0; i < 4; i++) {
        w.write(words[i] + " ");
    }
    w.flush();
    w.close();
}