Home  >  Article  >  Java  >  Java Arrays class usage example analysis

Java Arrays class usage example analysis

WBOY
WBOYforward
2023-05-12 08:16:14873browse

1.toString method

Outputs the array as a string according to the default format.

public static void main(String[] args) {
    int dataA[] = new int[] {1,2,5,4,3};
    System.out.println(Arrays.toString(dataA));
}

2.sort method

Sort the array in ascending order.

Note

Parameter array analysis

(1) is a numerical value, the default is ascending order

(2) is a string (English) in ascending alphabetical order Sorting

(3) It is a string (Chinese) sorted in ascending order according to the encoding number of the string

(4) If it is a custom type, then the custom class must have a comparable or Comparator interface Support

int[] intTest={15,78,32,5,29,22,17,34};
Arrays.sort(intTest);
output(intTest);

3.equals

Compares whether array elements are equal.

int []arr1 = {1,2,3};
int []arr2 = {1,2,3};
System.out.println(Arrays.equals(arr1,arr2));

Note: If the element values ​​of two arrays are the same, but the corresponding position elements of the two arrays are different, the return result of Arrays.equals is false.

The above is the detailed content of Java Arrays class usage example analysis. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete