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 class name to string 
Java :: set textView.android:drawableEnd programmatically 
Java :: sorting java 
Java :: java inline conditional 
Java :: java swing menu click event 
Java :: arraylist replace value java 
Java :: como ordenar un arraylist alfabeticamente en java 
Java :: iterate hashmap java 
Java :: final in java 
Java :: java printf tab 
Java :: java substring after character 
Java :: how to go to next iteration of while loop java 
Java :: get element in arraylist java 
Java :: How to efficiently find the area of largest rectangle that can be formed by adjacent buildings with known heights, in Java? 
Java :: stringbuffer in java 
Java :: hexstring to string In java 
Java :: for cicle java 
Java :: apache commons collections android dependency 
Java :: character types java 
Java :: java swing windows 10 look and feel 
Java :: android get last crash adb 
Java :: chenge font android studio 
Java :: java types of list 
Java :: loop through number java 
Java :: basic java programs 
Java :: delet file from path android 
Java :: java how to create an array 
Java :: how to add a listener to a toggle group radio buttons javafx 
Java :: java list last element 
Java :: linked list java 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =