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.

array diagram

Map of Array implementations

you are here

Part 1 – Array implementation
Part 2 – Sorted array implementation
Part 3 – Matrix 2D array basic operations

Table of Content


Add element in Array

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
Data Structures Illustrated Python Book

Why do you implement your own Array class?

array implementation

The implementation of your own class will help you understand how data structure works under the hood. You are able to tune the code to run fast and efficiently when needed.