The array objects support the following attributes and methods.
Array Methods (Python)
a.typecode— the typecode character used to create the array.a.itemsize— size, in bytes, of items stored in the array.a.append(x)— appends itemxto the end of the array.a.buffer_info()— returns the memory location and length of the buffer used to store the array.a.byteswap()— swaps the byte order of each item. Used for writing to a machine or file with a different byte order.a.count(x)— returns the number of occurrences ofxina.a.extend(b)— appends any iterable,b, to the end of arraya.a.frombytes(s)— appends items from a string,s, as an array of machine values.a.fromfile(f, n)— readsnitems, as machine values, from a file objectf, and appends them toa. Raises anEOFErrorif there are fewer thannitems available.a.fromlist(l)— appends items from listl.a.fromunicode(s)— extendsawith unicode strings. Arrayamust be of typeuor elseValueErroris raised.a.index(x)— returns the first (smallest) index of itemx.a.insert(i, x)— inserts itemxbefore indexi.a.pop([i])— removes and returns the item at indexi. Defaults to the last item (i = -1) if not specified.a.remove(x)— removes the first occurrence of itemx.a.reverse()— reverses the order of items.a.tobytes()— converts the array to machine values and returns the bytes representation.a.tofile(f)— writes all items, as machine values, to file objectf.a.tolist()— converts the array to a list.a.tounicode()— converts an array to a unicode string. The array type must beuor else aValueErroris raised.
Implementing an Array in Java
import java.util.Arrays;
public class Main { public static void main(String[] args) { // Declaring an array int arr[] = {8, 5, 3, 10, 2, 1, 15, 20};
// Sorting the array Arrays.sort(arr);
// Taking an element to search int ele = 15;
// Using binarySearch() method to search "ele" System.out.println( ele + " presents at the index = " + Arrays.binarySearch(arr, ele)); }}