Arrays class sort () array elements in ascending descending order

Source: Internet
Author: User

/* Use arrays class sort () array elements in ascending descending order
* * @Author: MO Smile scholar
* @Version: 2010-1-2 V1.0
*/
Import Java.util.Arrays;

Class Sortdemo
{
public static void Main (string[] args)
{
Int[] vec={0,15,-14,45,20,70};
Arrays.sort (VEC);

System.out.println ("Ascending rank:");
for (int i=0;i<vec.length; i++)
{
System.out.print (vec[i]+ "");
}
System.out.println ("n");
System.out.println ("descending order:");
for (int i=vec.length-1;i>=0; i--)
{
System.out.print (vec[i]+ "");
}

}
}

The following articles come from the network:

The Java.util.arrays class can be sorted, compared, and populated with arrays. These methods throw a Nullpointexception exception when the specified array object is null.

This class inherits directly from the Java.lang.object class.

1.sort () method
This method arranges the given array in ascending order, mainly in the following two syntactic formats:
(1) static void sort (byte[] a)
Sort all the elements in array a in ascending order
(2) static void sort (byte[] A, int fromindex, int toindex)
Arranges the elements in array a from fromindex (including) to the Toindex (excluding) intervals in ascending order
Note:

The data type of the array can be int[] byte[] short[] float[] long[] double[] char[, etc., even though

Object[] Type, which requires that all elements in the array must implement the comparable interface, which is to ensure that the

E1.compareto (E2) does not throw a classcastexception exception.

There are no descending-order parameters, and the data can be cycled from back to front in descending order


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.