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:MainClass.java

public static void main(String[] a) {
    int array[] = { 2, 5, -2, 6, -3 };
    Arrays.sort(array);
    for (int i : array) {
        System.out.println(i);/* www.  ja v  a 2  s .co m*/
    }
}

From source file:Main.java

public static void main(String[] args) {
    int intArray[] = { 1, 2, 4, 5 };
    Arrays.sort(intArray);
    int searchValue = 2;
    System.out.println(Arrays.binarySearch(intArray, searchValue));

    searchValue = 3;//from  w w  w  .ja v a2 s . com
    System.out.println(Arrays.binarySearch(intArray, searchValue));
}

From source file:Main.java

public static void main(String[] args) {
    short shortArray[] = { 1, 2, 4, 5 };
    Arrays.sort(shortArray);

    short searchValue = 2;
    System.out.println(Arrays.binarySearch(shortArray, searchValue));

    searchValue = 3;//from   w  w  w  .  ja  v  a  2  s  .c  o m
    System.out.println(Arrays.binarySearch(shortArray, searchValue));
}

From source file:Main.java

public static void main(String[] args) {
    byte bArray[] = { 1, 2, 4, 5 };
    Arrays.sort(bArray);

    byte searchValue = 2;

    int intResult = Arrays.binarySearch(bArray, searchValue);
    System.out.println("Result of binary search of 2 is : " + intResult);

    searchValue = 7;/*from   w ww .  j a  v  a 2 s. c o m*/
    intResult = Arrays.binarySearch(bArray, searchValue);
    System.out.println("Result of binary search of 3 is : " + intResult);
}

From source file:Main.java

public static void main(String[] args) {
    long longArray[] = { 1L, 2L, 4L, 5L };
    Arrays.sort(longArray);

    long searchValue = 2L;
    System.out.println(Arrays.binarySearch(longArray, searchValue));

    searchValue = 3;//from  w w w.j a v a2  s .  c o  m
    System.out.println(Arrays.binarySearch(longArray, searchValue));
}

From source file:Main.java

public static void main(String args[]) {
    String[] myArray = new String[] { "A", "a", "B" };
    Arrays.sort(myArray);
    System.out.println(Arrays.toString(myArray));
}

From source file:Main.java

public static void main(String[] args) {
    char charArray[] = { 'a', 'b', 'd', 'e' };
    Arrays.sort(charArray);

    char searchValue = 'b';
    System.out.println(Arrays.binarySearch(charArray, searchValue));

    searchValue = 'z';
    System.out.println(Arrays.binarySearch(charArray, searchValue));

}

From source file:Main.java

public static void main(String[] args) {
    int items[] = { 5, 4, 6, 1, 8, 9, 6, 7, 3, 2 };

    Arrays.sort(items);

    int index = Arrays.binarySearch(items, 1);

    System.out.println("Search item found at: " + index);
}

From source file:Main.java

public static void main(String[] args) {
    float floatArray[] = { 1.2f, 2.1f, 4.7f, 5.3f };
    Arrays.sort(floatArray);

    float searchValue = 4.7f;
    System.out.println(Arrays.binarySearch(floatArray, searchValue));

    searchValue = 3.3f;//from  ww w  .j a  va  2  s  . com
    System.out.println(Arrays.binarySearch(floatArray, searchValue));
}

From source file:Main.java

public static void main(String[] args) {
    double doubleArray[] = { 1.3, 2.1, 4.7, 5.3 };
    Arrays.sort(doubleArray);

    double searchValue = 4.7;

    System.out.println(Arrays.binarySearch(doubleArray, searchValue));

    searchValue = 3.33;//from   w  ww . j  a v a2s  . c o  m
    System.out.println(Arrays.binarySearch(doubleArray, searchValue));
}