Well-off accompany you to learn Java--------Sort method sorting an array

Source: Internet
Author: User

This article and you share another array of operations methods--sort methods to sort the arrays.

Example: Testjava4_5.java

01//The following program is an array of sort operations, where the sort method is used to sort the arrays

java.util.* import;

public class Testjava4_5

04 {

public static void Main (string[] args)

06 {

-int a[] = {4,32,45,32,65,32,2};

08

System.out.print ("Order of the array before sorting:");

Ten for (int i=0;i<a.length;i++)

One System.out.print (a[i]+ "");

Arrays.sort (a); Sorting Methods for arrays

System.out.print ("\ n the order of the array after sorting:");

+ for (int i=0;i<a.length;i++)

System.out.print (a[i]+ "");

16}

17}

Output Result:

Order of array before sorting: 4 32 45 32 65 32 2

Order of the array after sorting: 2 4 32 32 32 45 65

The 12th line of the program Arrays.sort (array name) array of operations, but this method in Java.util this package, so in the use of the time need to import it, about the concept of the package, the small part will be in the future sharing with everyone to learn. As I said before, the current study may encounter some problems can not be fully understood, do not go into a dead end, or it will hinder everyone's learning progress, beginners in contact with Java by constantly knocking code, like "book read times, its righteousness from the present" the same truth.

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.