Overview of Java Arrays


<aside> <img src="/icons/table_red.svg" alt="/icons/table_red.svg" width="40px" /> Table of Contents

</aside>

<aside> 💡

  1. Java Arrays </aside>

<aside> 💡

  1. Single-Dimensional Array in Java </aside>

<aside> 💡

  1. Multidimensional Array in Java </aside>

Java Arrays


  1. Java Arrays

    1. An array is typically a grouping of elements of the same kind that are stored in a single, contiguous block of memory.

    2. Java array is an object which contains elements of a similar data type. Additionally, The elements of an array are stored in a contiguous memory location. It is a data structure where we store similar elements. We can store only a fixed set of elements in a Java array.

    3. Array in Java is index-based, the first element of the array is stored at the 0th index, 2nd element is stored on 1st index and so on.

    4. In contrast to C/C++, the length member allows us to obtain the array's length. We must utilise the sizeof operator in C/C++.

    5. An object of a dynamically formed class is called an array in Java. Java arrays implement the Serializable and Cloneable interfaces and derive from the Object class. In Java, an array can hold objects or primitive values. Java allows us to create single- or multi-dimensional arrays, just like C/C++ does.

    6. Additionally, C/C++ does not support the anonymous array functionality that Java does.

      image.png


  2. Advantages and Disadvantages of Arrays

    1. Advantages:
      1. Code Optimization: It makes the code optimized, we can retrieve or sort the data efficiently.
      2. Random access: We can get any data located at an index position.
    2. Disadvantages
      1. Size Limit: Arrays have a fixed size and do not grow dynamically at runtime.

  3. Types of Array in java

    1. There are two types of array.
      1. Single Dimensional Array
      2. Multidimensional Array