CARVIEW |
Select Language
HTTP/2 200
cache-control: public, max-age=300, stale-while-revalidate=604800
referrer-policy: strict-origin-when-cross-origin
x-app-version: v251008-h-251010-1202
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-app-type: Learn
x-middleware-rewrite: /answers/howdev/array-vs-arraylist-in-java
x-nextjs-cache: MISS
etag: W/"uqkwcx55u4pup0"
content-type: text/html; charset=utf-8
x-cloud-trace-context: eca8d303f8a8a92a05a7caa4189724c9;o=1
date: Sat, 11 Oct 2025 19:53:43 GMT
server: Google Frontend
via: 1.1 google
vary: Accept-Encoding
content-encoding: gzip
x-cache-status: miss
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Array vs. ArrayList in Java 

Array vs. ArrayList in Java
In Java programming, there are two ways to create an array.
-
Array
: Is a simple fixed-size data structure which requires a size at the time of creation. -
ArrayList
: Is a dynamic sized data structure which doesn’t require a specific size at the time of initialization.
Array
An Array
can contain both primitive data types or objects of a class depending on the definition of the array. But it has a fixed size.
Example
// Importing the required librariesimport java.util.Arrays;class Array{public static void main(String args[]){/* ...........Array............. */// Fixed size.// Cannot add more than 3 elements.int[] arr = new int[3];arr[0] = 5;arr[1] = 6;arr[2] = 10;// PrintingSystem.out.println(Arrays.toString(arr));}}
ArrayList
An ArrayList
can’t be created for primitive data types. It only contains an object. It has the ability to grow and shrink dynamically.
- Remember that in Java, every primitive data type has a wrapper class.
| Primitive | Wrapper class |
| — | — |
|
int
|Integer
| |short
|Short
| |byte
|Byte
| |char
|Character
| |float
|Float
|
Example
// Importing required librariesimport java.util.ArrayList;class Array_List{public static void main(String args[]){/*............ArrayList..............*/// Variable size.// Can add more elements.ArrayList<Integer> arr = new ArrayList<Integer>();arr.add(5);arr.add(9);arr.add(11);// PrintingSystem.out.println(arr);}}
Relevant Answers
Explore Courses
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved