Detailed Explanation of Class Arrays and Class Math in Java

  • 2021-07-09 07:58:14
  • OfStack

Arrays (Array Utility Class)

Encapsulated classes in Java provide a large number of static methods for users to use arrays.

Guide package: import java. util. Arrays

1. Arrays. toString (Array)//The return value is a string enclosed by [], and the elements in the array are placed in []


 int[] arr=new int[]{1,2,3,4};
    String str=Arrays.toString(arr);
    System.out.println(str);
 --------------------------------
 [1,2,3,4]

2. Arrays. sort (Array)//No return value, sorts the array, (ascending from small to large) the array has changed


int[] arr=new int[]{3,27,46,1,48};
//    String str=Arrays.toString(arr);
//    System.out.println(str);
    Arrays.sort(arr);
    for(int i=0;i<arr.length;i++){
        System.out.print(arr[i]);    
}
===========================
1 3 27 46 48

Math (Mathematics)

Guide package: import java. lang (omitted)

a. Math. abs (numeric value)//Returns the absolute value of the numeric value

b. Math. ceil (numeric value)//Returns upward rounding of a numeric value

c. Math. floor (numeric)//Returns downward rounding of an array

d. Math. roud (numeric value)//Returns a numeric value rounded by 4

e. Math. PI//Value of pi


Related articles: