1/25
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Array
A data structure that allows you to store multiple values of the same type in a single variable.
One single type
An array is a collection of similar types of data. It is a container that holds values of ________.
Fixed Size
Same Type
Indexed Access
Characteristics of Arrays
Fixed Size
Once declared, the size of the array cannot be changed.
Same Type
All elements in an array must be of the same type.
Indexed Access
Array elements are accessed using an index, starting at 0.
One-Dimensional Array
Two-Dimensional Array
Types of Arrays
One-Dimensional Array
Essentially a list of elements, all of the same data type, organized in a single row. Think of it as a straight line of values.
Stores a sequence of elements.
Accessed using a single index (starting from 0).
Ideal for linear data like scores, prices, or names
Characteristics of One-Dimensional Array
Two-Dimensional Array
Like a table or matrix. It consists of rows and columns, where each element is identified using two indices: one for the row and one for the column.
Represents data in tabular form.
Accessed using two indices: array[row][column].
Useful for data like grids, matrices, or board games (e.g., chess).
Characteristics of Two-Dimensional Array
dataType[] arrayName;Syntax declaration of One-Dimensional Array
dataType[] [] arrayName;Syntax declaration of Two-Dimensional Array
Stored in a contiguous block of memory.
Memory representation of one-dimensional array.
Rows stored as separate blocks, each containing elements.
Memory representation of two-dimensional array.
Storing a lists of items like student names or scores.
Example of one-dimensional array
Storing tabular data like timetable or image pixels.
Example of two-dimensional array
Insertion
Deletion
Searching
Sorting
What are some common operations performed on Arrays?
Insertion
Adding an element to the array
Deletion
Removing an element from the array.
Searching
Finding the position of an element in the array.
Sorting
Ordering elements in a particular order like ascending or descending.
Inserting Elements (changing an element by index)
You can change the value of an array element by directly assigning a new value to it using its index.
Searching for an Element
To find an element, you typically use a loop to check each element in the array.
Sorting an array
Java provides the Arrays class with a sort() method to sort arrays in ascending order.
You can use Arrays.copyOf() or System.arraycopy() to copy arrays in Java.
How do you copy an Array?