List of usage examples for java.util Arrays sort
public static void sort(Object[] a)
From source file:MainClass.java
public static void main(String[] args) { int[] intArray = new int[] { 5, 4, 3, 2, 1 }; Arrays.sort(intArray); for (int i : intArray) { System.out.println(i);/* w w w .j ava 2 s. c om*/ } }
From source file:Main.java
public static void main(String[] args) { int a[] = new int[] { 1, 2, 4, 1, 5, 7, 3, 4 }; Arrays.sort(a); int min = a[0]; System.out.println("The minmum value is " + min); int max = a[a.length - 1]; System.out.println("The maxemum value is " + max); for (int i = 0; i < a.length; i++) { System.out.println(a[i]); }//from ww w.j ava 2 s.c o m }
From source file:MainClass.java
public static void main(String args[]) throws Exception { String[] a = new String[] { "A", "C", "B" }; Arrays.sort(a); for (int i = 0, n = a.length; i < n; i++) { System.out.println(a[i]); }//from ww w . ja v a 2 s. com }
From source file:Main.java
public static void main(String[] args) { String names[] = { "W", "M", "N", "K" }; Arrays.sort(names); for (int i = 0; i < names.length; i++) { String name = names[i];/*from ww w .j a va 2 s .com*/ System.out.print("name = " + name + "; "); } Person persons[] = new Person[4]; persons[0] = new Person("W"); persons[1] = new Person("M"); persons[2] = new Person("N"); persons[3] = new Person("K"); Arrays.sort(persons); for (int i = 0; i < persons.length; i++) { Person person = persons[i]; System.out.println("person = " + person); } }
From source file:Main.java
public static void main(String[] a) { String str[] = { "B", "H", "L", "M", "I", "N", "R" }; // Ensure list sorted Arrays.sort(str); for (String s : str) { System.out.println(s);/* w w w . j a va 2 s . co m*/ } // Search for element in list int index = Arrays.binarySearch(str, "M"); System.out.println("Found M @ " + index); }
From source file:Main.java
public static void main(String[] args) { int[] intArray = new int[] { 4, 5, 9, 0, 3, 5, 6, 2 }; Arrays.sort(intArray); for (int i = 0; i < intArray.length; i++) System.out.println(intArray[i]); String[] stringArray = new String[] { "D", "E", "A", "C", "B" }; Arrays.sort(stringArray);//w w w. ja v a 2s . com for (int i = 0; i < stringArray.length; i++) System.out.println(stringArray[i]); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { int array[] = { 2, 5, -2, 6, -3, 8, 0, -7, -9, 4 }; Arrays.sort(array); printArray("Sorted array", array); int index = Arrays.binarySearch(array, 2); System.out.println("Found 2 @ " + index); index = Arrays.binarySearch(array, 1); System.out.println("Didn't find 1 @ " + index); int newIndex = -index - 1; array = insertElement(array, 1, newIndex); printArray("With 1 added", array); }
From source file:Main.java
public static void main(String[] argv) { String[] strings = { "10", "9", "100" }; Arrays.sort(strings); for (String string : strings) System.out.print(string + " "); }
From source file:Main.java
public static void main(String[] argv) throws Exception { int[] intArray = new int[] { 4, 1, 3, -23 }; Arrays.sort(intArray); // [-23, 1, 3, 4] String[] strArray = new String[] { "z", "a", "C" }; Arrays.sort(strArray);//from w w w .j a v a2 s. co m // [C, a, z] // Case-insensitive sort Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER); // [a, C, z] // Reverse-order sort Arrays.sort(strArray, Collections.reverseOrder()); // [z, a, C] // Case-insensitive reverse-order sort Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER); Collections.reverse(Arrays.asList(strArray)); // [z, C, a] }
From source file:Main.java
public static void main(String[] args) { char cArr[] = { 'j', 'a', 'v', 'a' }; System.out.println(Arrays.toString(cArr)); // sorting array Arrays.sort(cArr); System.out.println(Arrays.toString(cArr)); }