Section 7 Arrays Tools

package cn.itcast.day08.demo04;

import java.util.Arrays;

/ *
Java.util.Arrays is associated with an array of tools, which provides a number of static methods used to implement an array of common operations.

public static String toString (array): The parameter array into a string (in accordance with the default format: [element 1, element 2, element .... 3])
public static void Sort (array): ascending order by default (small to large) of the elements of the array to be sorted.

Notes:
1. If the value is, sort in ascending order from small to large default
2. If a string, sort in ascending alphabetical order according to the default
3. If a custom type, this custom class is needed to support the interface Comparable or Comparator . (Future learning)
* /
public class Demo01Arrays {

static void main public (String [] args) {
int [] = {intArray 10, 20 is, 30};
// the int [] array in accordance with the default format string into
String = intStr of Arrays.toString (intArray);
the System. out.println (intStr); // [10 , 20, 30]

int[] array1 = {2, 1, 3, 10, 6};
Arrays.sort(array1);
System.out.println(Arrays.toString(array1)); // [1, 2, 3, 6, 10]

String[] array2 = {"bbb", "aaa", "ccc"};
Arrays.sort(array2);
System.out.println(Arrays.toString(array2)); // [aaa, bbb, ccc]
}

}

Guess you like

Origin www.cnblogs.com/curedfisher/p/12375779.html