/* 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