About 6,190,000 results
Open links in new tab
  1. Sort an array in Java - Stack Overflow

    Aug 1, 2017 · just FYI, you can now use Java 8 new API for sorting any type of array using parallelSort. parallelSort uses Fork/Join framework introduced in Java 7 to assign the sorting tasks to multiple threads available in the thread pool. the two methods that can be used to sort int array, parallelSort(int[] a) parallelSort(int[] a,int fromIndex,int toIndex)

  2. Arrays.sort() in Java - GeeksforGeeks

    Apr 8, 2025 · The Arrays.sort() method is used for sorting the elements in an Array. It has two main variations: Sorting the entire array (it may be an integer or character array) Sorting a specific range by passing the starting and ending indices. Below is a simple example that uses the sort() method to arrange an array of integers in ascending order.

  3. Java How To Sort an Array - W3Schools

    You can use the sort() method, found in java.util.Arrays, to sort an array: Example import java.util.Arrays; public class Main { public static void main(String[] args) { String[] cars = {"Volvo", "BMW", "Tesla", "Ford", "Fiat", "Mazda", "Audi"}; Arrays.sort(cars); for (String i : cars) { System.out.println(i); } } }

  4. Java Arrays. sort() Method - W3Schools

    The sort() method sorts an array in ascending order. This method sorts arrays of strings alphabetically, and arrays of integers numerically. Required. The array to be sorted. Optional. The index position of the first element (inclusive) to be sorted. Optional. The index position of the last element (exclusive) to be sorted. Java Arrays Tutorial.

  5. Sorting in Java - GeeksforGeeks

    Mar 15, 2024 · So there is sorting done with the help of brute force in java with the help of loops and there are two in-built methods to sort in Java. Ways of sorting in Java. Let us discuss all four of them and propose a code for each one of them. Way 1: Using loops. Way 2: Using sort () method of Arrays class.

  6. java - Sorting int array in descending order - Stack Overflow

    For primitive array types, you would have to write a reverse sort algorithm: Alternatively, you can convert your int[] to Integer[] and write a comparator: @Override. public int compare(Integer o1, Integer o2) { return o2.compareTo(o1); or use Collections.reverseOrder() since it only works on non-primitive array types. and finally,

  7. How to Sort an Array in Java 8 - Java Guides

    In Java 8, you can sort arrays using the Arrays.sort() method for basic sorting in ascending order, or you can use Streams for more flexibility, including sorting in descending order. Both approaches are efficient and easy to implement, and you …

  8. Sorting Arrays in Java - Baeldung

    Jan 8, 2024 · Java’s util.Arrays.sort method provides us with a quick and simple way to sort an array of primitives or objects that implement the Comparable interface in ascending order. When sorting primitives, the Arrays.sort method uses a Dual-Pivot implementation of Quicksort. However, when sorting objects an iterative implementation of MergeSort is used.

  9. How to Sort an Array, List, Map or Stream in Java

    Java program to sort an array of integers in ascending order using Arrays.sort() method. //Unsorted array Integer[] numbers = new Integer[] { 15, 11, ... }; //Sort the array Arrays.sort(numbers);

  10. Java Arrays sort() Method - Online Tutorials Library

    Java Arrays sort () Method - Learn how to sort arrays in Java using the sort () method. Explore examples and syntax for efficient array sorting.

  11. Some results have been removed
Refresh