import java.util.ArrayList;

public class Demo{
    public static void main(String[] args) {
        ArrayList<String> fruits = new ArrayList<String>();
        fruits.add("apple");
        fruits.add("pineapple");
        fruits.add("pineapple");
        fruits.add("pears");
        fruits.add("oranges");
        
        for (int i = 0; i < fruits.size(); i++) {
            System.out.println(fruits.get(i)); 
        }
    }
}
Demo.main(null)

Fixed length: Once an array is created, we cannot change its size. So consider using arrays when the numbers of elements are known and fixed. Otherwise, you should consider using another dynamic container such as ArrayList. It’s very fast to access any elements in an array (by index of the elements) in constant time: accessing the 1st element takes same time as accessing the last element. So performance is another factor when choosing arrays. An array can hold primitives or objects, stores values of the primitives. An array of objects stores only the references to the objects. In Java, the position of an element is specified by index which is zero-based. That means the first element is at index 0, the second element at index 1, and so on. An array itself is actually an object.

//Hack 1

import java.util.ArrayList; 

public class hack1 {
    public static void main (String[] args) {
       ArrayList<Integer> testArray = new ArrayList<Integer>(); 
       testArray.add(103);
       testArray.add(3);
       testArray.add(12312312);
       System.out.println(testArray.size()); 
    }
}

hack1.main(null);
3
//Hack 2
import java.util.ArrayList;

ArrayList<String> color = new ArrayList<String>(); 
color.add("red apple");
color.add("green box");
color.add("blue water");
color.add("red panda");

for (int i = 0; i < color.size(); i++) {
    if (color.get(i).contains("red")) {
        color.remove(i); 
    } 
}

System.out.println(color);
[green box, blue water]
//Hack 3

ArrayList<Integer> num = new ArrayList<Integer>(); 

num.add(6);
num.add(1);
num.add(1);

int sum = 0; 

for (int number : num) {
    sum += number;
}
System.out.println(sum);
8