How to sort an array of numbers in ascending order with Java

1 Answer

0 votes
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        Integer[] arr = new Integer[] {5, 3, 7, 1, 5, 2, 9, 8};

        Arrays.sort(arr);
        
        System.out.println(Arrays.toString(arr));
    }
}




/*
run:

[1, 2, 3, 5, 5, 7, 8, 9]

*/

 



answered May 29, 2021 by avibootz

Related questions

...