How do I sort array values in descending order?

Category: java.util, viewed: 27731 time(s).

Here you'll find an example how to sort array's values and sort it in ascending or descending order.

package org.kodejava.example.util;

import java.util.Arrays;
import java.util.Collections;

public class SortArrayWithOrder {
    public static void main(String[] args) {
        Integer[] points = new Integer[5];
        points[0] = 94;
        points[1] = 53;
        points[2] = 70;
        points[3] = 44;
        points[4] = 64;

        //
        // Sort the points array, the default order is in ascending order.
        // [44, 53, 64, 70, 94]
        //
        Arrays.sort(points);
        System.out.println(Arrays.toString(points));

        //
        // Sort the points array in descending order.
        // [94, 70, 64, 53, 44]
        //
        Arrays.sort(points, Collections.reverseOrder());
        System.out.println(Arrays.toString(points));
    }
}
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats