0% found this document useful (0 votes)
4 views11 pages

Understanding Arrays in Programming

na
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views11 pages

Understanding Arrays in Programming

na
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

What is an Array?

• • A container object that holds a fixed


number of values of a single type.
• • Length is fixed once created.
• • Each element is accessed by its index.
Why Use Arrays?

• • Efficient way to store multiple values


• • Useful in loops and data operations
• • Easy to sort and search
Array Declaration and Initialization

• int[] numbers = new int[5];


• int[] marks = {90, 85, 75, 60, 95};
Accessing Array Elements

• [Link](marks[0]); // Output: 90
• • Index starts from 0
• • Accessed via arrayName[index]
Array Length and Looping

• for(int i = 0; i < [Link]; i++) {


• [Link](marks[i]);
• }
• • length gives element count
Types of Arrays

• 1. Single Dimensional Array


• 2. Multidimensional Array (e.g., 2D arrays)
Multidimensional Array Example

• int[][] matrix = {
• {1, 2, 3},
• {4, 5, 6},
• {7, 8, 9}
• };
• Access: matrix[0][2] → 3
Common Operations

• • Traversing
• • Updating elements
• • Sorting ([Link]())
• • Searching ([Link]())
Example Program

• import [Link];

• class Example {
• public static void main(String[] args) {
• int[] arr = {5, 2, 8, 1};
• [Link](arr);
• for (int num : arr) {
• [Link](num + " ");
• }
Summary

• • Arrays hold multiple values of same type


• • Can be 1D or multidimensional
• • Useful for managing data
Thank You

• Questions?
• Contact Info / References

You might also like