# String Arrays in java
● What is an Array..?
An Array is a collection of elements of the same data types stored in a contiguous
memory location.
Array allows to store multiple values in a single variable
❖ It allows random access using indexes.
❖ The size of the array is fixed once created.
Example:
Normal code> int num1 = 10, num2 = 20, num3 = 30…………50
array> int numbers[ ] = {10, 20, 30,..50};
“ [ ] “ it is the size of an array
Syntax:
indexes:(memory allocation)
Declaring and initialization:
Direct initialization:
# Primitive Array:
Definition
A primitive array is an array that stores primitive data types such as:
Int , float, double, char, boolean, byte, short, long.
Each element stores an actual value, not a reference.
● Each cell directly contains the value (like 1, 2….etc.).
● No Object references here – only actual primitive values.
$ Key points about primitive array:
● Stores actual values
● Faster in access and processing.
● Less memory used.
● Can’t call methods on elements(bcz they are not obj.)
● Default value(if not initialized)
○ Int = 0
○ Float = 0.0
○ Boolean = false
○ Char = ‘\u0000’
#OBJECT ARRAY(Array of non primitive/ reference types)
Definition:
An object array is an array that stores references (Addresses) to objects, not primitive values
directly.
Each element refers to an object in heap memory.
Example obj array of a single class: