METHODS - Array

5 flashcards · Other · by Steven Bui

  1. Arrays.sort(array)

    O(n log n) Uses the quick sort algorithm to sort arrays of primitive types (int, char) RETURN: void - the given array is sorted

  2. Arrays.binarySearch(array, element)

    O(log n) Binary search is an O(log n) algorithm. RETURN: int - index of the element

  3. Arrays.equals(array, array)

    O(n) Iterates through the length of both arrays. RETURN: boolean - if the arrays are equal

  4. Arrays.copyOf(array, new_length)

    O(n) Iterates through the length of the array to the given length. RETURN: array[] - copy of the array

  5. array.length

    O(1) The length is a field. RETURN int - length of the array