Using arrays in Java

In Java, an array is a container object that holds values of a single type. The length of an array is established when the array is created and cannot be changed. To declare an array in Java, you specify the type of the elements followed by square brackets, then the array's name. For initialization, you can use the 'new' keyword followed by the data type and the number of elements you want the array to contain inside square brackets. You can initialize the Java array with specific values by enclosing them in curly braces {}. Once declared, individual elements in the array can be accessed using the array name followed by the index (starting from 0) in square brackets. In this Java Array Example, we create an array and initialize it with specific values by enclosing them in curly braces {}. Click Execute to run the Java Array Example online and see the result.
Using arrays in Java Execute
public class ArrayExample {
    public static void main(String[] args) {
        int[] numbers = new int[3];
        numbers[0] = 10;
        numbers[1] = 20;
        numbers[2] = 30;
        for (int number : numbers) {

        String[] names = {"Alice", "Bob", "Charlie"};
        for (String name : names) {
Updated: Viewed: 41 times