An array is an index-based data structure, which means every element is referred by an index.  Array data are stored in sequential memory. The index runs from 0 to the array size minus one. The size of an array should be specified when initializing an array in Java. Here is implementation of array operations – add, remove, search and traversal.

Table of Content


Add element

Add element at the end, or at the given index. In Java, you need check whether you have reached the max size.

Java

Javascript

Python

Doodle

array add


Delete element

Delete the element by key or by index. You need to move the following elements to their preceding position.

Java

Javascript

Python

Doodle

array delete


Linear search

Starting from the index 0, compare each element in the array with the key . Return the first matched element’s index. If the key is not found, return -1.

Java

Javascript

Python

Doodle

array search


Print elements

Print all elements in the array from index 0 to the last.

Java

Javascript

Python

Doodle

array search

Download Java, JavaScript and Python code
Array animated
Data structures and Java collections