Java Array

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.

package anote;

public class Main {
    public static void main(String[] args) {

        int[] myVar = new int[10];
        double[] myDouVar = { 50.2, 40.3, 60.7, 90.0 };
        String[] myCars = { "BMW", "KIA" };

        myVar[5] = 30;
        System.out.println(myVar[5]);
        System.out.println(myCars[1]);
        System.out.println("---");
        for (int i = 0; i < myDouVar.length; i++) {
            System.out.println(myDouVar[i]);
        }
    }
}
30
KIA
---
50.2
40.3
60.7
90.0

Leave a Reply

Your email address will not be published.

ANOTE.DEV