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

PREVIOUS NEXT
Code Example
Java :: java replace first occurrence of substring 
Java :: number of digits java 
Java :: spring scheduled 
Java :: last char in string java 
Java :: java arraylist deepcopy 
Java :: java count to 10 
Java :: long vs int java 
Java :: fill two dimensional array rows by rows java 
Java :: android application class 
Java :: sudoku solver 
Java :: intellij 
Java :: java get first day of the week 
Java :: if is true javascrtiptr 
Java :: change string to char array 
Java :: java math power 
Java :: how to initialize array in java with 0 
Java :: loop through treeset java 
Java :: object vs class c# 
Java :: java sort int array 
Java :: which api is android 12 
Java :: convert two bytes to int java 
Java :: initialize a new class java 
Java :: how to find prime numbers in java 
Java :: How to efficiently find the area of largest rectangle that can be formed by adjacent buildings with known heights, in Java? 
Java :: how to use user uid in android 
Java :: Java Sorting Using sort() 
Java :: spring security auto login after register 
Java :: java swing windows 10 look and feel 
Java :: how to sum a 2d array in java 
Java :: uses or overrides a deprecated API. 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =