Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

sort an int array java

import java.util.Arrays;
 
class GFG {
    public static void main(String args[])
    {
        int[] arr = { 5, -2, 23, 7, 87, -42, 509 };
        System.out.println("The original array is: ");
        for (int num : arr) {
            System.out.print(num + " ");
        }
        Arrays.sort(arr);
        System.out.println("
The sorted array is: ");
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }
}
Comment

java sort int array

// an array of ints
int[] arr = {1, 2, 3, 4, 5, 6};

// an array of reverse sorted ints
int[] arrDesc = Arrays.stream(arr).boxed()
    .sorted(Collections.reverseOrder())
    .mapToInt(Integer::intValue)
    .toArray();

System.out.println(Arrays.toString(arrDesc)); // outputs [6, 5, 4, 3, 2, 1]
Comment

java sort array int

Arrays.sort(arr)
Comment

sort an int array java

import java.util.Arrays;
 
class GFG {
    public static void main(String args[])
    {
        int[] arr = { 5, -2, 23, 7, 87, -42, 509 };
        System.out.println("The original array is: ");
        for (int num : arr) {
            System.out.print(num + " ");
        }
        Arrays.sort(arr);
        System.out.println("
The sorted array is: ");
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }
}
Comment

java sort int array

// an array of ints
int[] arr = {1, 2, 3, 4, 5, 6};

// an array of reverse sorted ints
int[] arrDesc = Arrays.stream(arr).boxed()
    .sorted(Collections.reverseOrder())
    .mapToInt(Integer::intValue)
    .toArray();

System.out.println(Arrays.toString(arrDesc)); // outputs [6, 5, 4, 3, 2, 1]
Comment

java sort array int

Arrays.sort(arr)
Comment

PREVIOUS NEXT
Code Example
Java :: finding min and max from given number in java 
Java :: Search a 2D Matrix II 
Java :: xml button color not changing 
Java :: calculate standard deviation in java 
Java :: arraylist remove value in java 
Java :: a ^ b java 
Java :: imperative programming paradigm example 
Java :: javafx initialize 
Java :: what to do in minecraft 
Java :: Android java toArray to String array 
Java :: Java Scanner nextDouble() 
Java :: code wars jaden casting java 
Java :: java.lang.NoClassDefFoundError: net/sf/cb2xml/def/IItem 
Sql :: mysql set safe mode off 
Sql :: get database size mysql 
Sql :: insert column after column mysql 
Sql :: sql finding longest and shortest names in a fleld 
Sql :: mysql find tables with name 
Sql :: view column data type sql 
Sql :: sql list all databases 
Sql :: how to restart mysql in linux 
Sql :: mysql database stopped xampp mac 
Sql :: get the next auto_increment value mysql 
Sql :: sql dateadd hours 
Sql :: mysql interval 1 day 
Sql :: group_concat length limit 
Sql :: t-sql remove all non-alphanumeric characters from a string 
Sql :: mysql remove unique constraint 
Sql :: psql view enum values 
Sql :: key validation sql 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =