Tools -Arrays java array operation

static int binarySearch (type [] a, type key) using the binary search method to search the index key element in the array; if the array does not include a key, returns a negative number. (This method must be invoked by the ascending order).

static int binarySearch (type [] a, int fromIndex, int toIndex, type key) using the binary search method to search for the key element in an array to toIndex from fromIndex index; if the array does not include a key, returns a negative number. (This method must be invoked by the ascending order).

static boolean [] copyOf (type [] original, int newLength) Copies the specified array See notes below

static byte [] copyOfRange (type [] original, int from, int to) copies the specified range of the array into a new array.

 

static boolean equals (type [] a, type [] a2) if the two arrays are equal in length and eleven elements are equal Returns true

static void fill (type [] a, type val) Ode to all array elements is a val.

static void fill (type [] a, int fromIndex, int toIndex, type val) from the formIndex to a array element Ode between tiondex index val. 

static void sort (type [] a) // sort (int [] arr) the specified array into ascending numerical order.

static void sort (type [] a, int fromIndex, int toIndex) to be specified array into ascending numerical order from the element between tiondex formIndex index.

static String toString (type [] a) Returns a string representation of the contents of an array. Separated by commas or spaces between the plurality of array elements.

 

My summary: using array tools can save time, improve efficiency, pay attention to regular inspection API ;

 

Eg:

package reviewDemo;

 

import java.util.Arrays;

 

// use the Arrays class

public class Demo4 {

    public static void main(String[] args) {

        int[] age = new int[] { 12, 26, 3, 60, 55, 6, 48, 4, 98 };

        The System. OUT .println (Arrays,. ToString (Age)); // printing out an array of methods

       

        int [] = {1,2,3,4,5,6,98,65,23 AGE2};

        int i = Arrays.binarySearch(age2, 98);

        System.out.println(i);

    }

}

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11131080.html