0% found this document useful (0 votes)
3 views4 pages

Java String and Array Basics

The document explains arrays in Java, defining them as collections of elements of the same data type stored in contiguous memory. It distinguishes between primitive arrays, which store actual values of primitive data types, and object arrays, which store references to objects. Key points include the fixed size of arrays, faster access for primitive arrays, and the inability to call methods on primitive array elements.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Java String and Array Basics

The document explains arrays in Java, defining them as collections of elements of the same data type stored in contiguous memory. It distinguishes between primitive arrays, which store actual values of primitive data types, and object arrays, which store references to objects. Key points include the fixed size of arrays, faster access for primitive arrays, and the inability to call methods on primitive array elements.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# 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:

You might also like