Java Language Learning summarizes the use of the advanced version of the array of tools Arrays! toString method, converted into a string of other types of array type, sort methods, automatic sorting

An array of tools Arrays

toString method and sort methods

toString method may be converted into an array of other types of string type .
sort () method is to sort the array, from small to large order is the default. String type may be sorted array.
Sample code:

import java.util.Arrays;
public class ToStringTest {

	public static void main(String[] args) {
		int[] intArray = {10,20,30};
		String intStr = Arrays.toString(intArray);
		System.out.println(intStr);
		
		int[] array1 = {3,6,5,2,8,99,1,10,20};
		Arrays.parallelSort(array1);
		System.out.println(Arrays.toString(array1));
		
		String[] array2 = {"aaa","bbb", "ccc"};
		Arrays.sort(array2);
		System.out.println(Arrays.toString(array2));

	}

}

Output:
Output

Examples

A character array of ascending, descending printing. code show as below:

import java.util.Arrays;
public class UpSort {

	public static void main(String[] args) {
		String str = "adg15ga5gadga615agg";
		
		char[] chars = str.toCharArray();
		Arrays.sort(chars);
		
		for(int i = chars.length-1;i>=0;i--) {
			System.out.print(chars[i] + " ");
		}
	}
}

FIG Output:
Output

——————————————————————

Published 50 original articles · won praise 3 · Views 5177

Guess you like

Origin blog.csdn.net/Ace_bb/article/details/104073111