Java Array and ArrayList difference explained below. Array and ArrayList are important concepts used mostly in day to day real project programming.
 
Array can be defined and initialize in two ways;

String[] weekdays1 = new String[7];
weekdays1[0] = "Sunday";
weekdays1[1] = "Monday";

String[] weekdays2 = {"Sunday","Monday"};

 
ArrayList can be defined and initialize as below;

ArrayList planets = new ArrayList<>();
planets.add("Sun");

Complete class ArrayAndArrayList.java can be found below;
 

package com.basic;

import java.util.ArrayList;

public class ArrayAndArrayList {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		String[] weekdays1 = new String[7];
		weekdays1[0] = "Sunday";
		weekdays1[1] = "Monday";
		weekdays1[2] = "Tuesday";
		weekdays1[3] = "Wednesday";
		weekdays1[4] = "Thursday";
		weekdays1[5] = "Friday";
		weekdays1[6] = "Saturday";
		
		String[] weekdays2 = {"Sunday","Monday"};
		
		System.out.println("3rd day in a week is:" + weekdays1[2]);
		System.out.println("2nd day in a week is:" + weekdays2[1]);
		
		ArrayList planets = new ArrayList<>();
		planets.add("Sun");
		planets.add("Earth");
		planets.add("Mars");
		planets.add("Pluto");
		
		System.out.println("First Planet is: "+planets.get(0));	
	}
}

 
Refer YouTube tutorial with detailed explanation
 

 
For official Java Docs refer https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
 
For further reading refer Java Programming Category posts.

Share this post

Learning Java Array and ArrayList difference
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *