About sorting java.util.Arrays class

Array sort

It's a new content, but I'll make a note to remember it.

java.util.Arrays class

If you declare an array and make it Arrays.sort (reference variable), the sort operation is over.

The sorting method of the Arrays class is Dual-Pivot Quicksort, which is faster than general quicksorting, so I think it's better to prioritize this without hesitation rather than implementing bubble sort and making mistakes yourself.

java


//what if{3,9,2,7,5}If so
int[] lists = new int[5];

//Sorting is complete at this point
Arrays.sort(lists);

//{2,3,5,7,9}Next list[0]Get 2
System.out.println(lists[0]);

//[1,2,3,4,5]Returns a string representation like
Arrays.toString(a);

//Output all sorted array
for(int list:lists){
    System.out.println(list+",");
}

Recommended Posts

About sorting java.util.Arrays class
About class inheritance.
About Java class
About the StringBuilder class
About class division (Java)
About Java StringBuilder class
[Java] About Singleton Class
[Swing] About JFrame class
About Java String class
About java abstract class
Find out about class methods
About the File :: Stat class
About Java class variables class methods
A murmur about the utility class
About =