Summary of sorting methods of sets and arrays in Java

According to the agreement, when using java programming, you should use the existing class library as much as possible. Of course, you can write a sorting method or framework yourself, but how many people can write better than those in JDK? Another advantage of using existing classes is that the code is easy to read and maintain. This article mainly talks about how to use existing class libraries to sort arrays and various collection containers (some examples in this article are from Java developers almanac 1.4)

First, you need to know two classes: Java util. Arrays and Java util. Collections (note the difference between collections) collection is the top-level interface of the collection framework, while collections contains many static methods. We use arrays to sort arrays and collections to sort combined framework containers, such as arrayslist, LinkedList, etc.

Import Java should be added to all examples util.* And other shell code, such as classes and static main methods, I will write all the code in the first example, and then omit it without exception.

Sort arrays

For example, there is an integer array:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>