Docsity

Arrays: A Convenient Way to Store Similar Data Types, Slides of Java Programming

Partial preview of the text

Download Arrays: A Convenient Way to Store Similar Data Types and more Slides Java Programming in PDF only on Docsity!

Arrays

Announcements

55 people answered the survey Wednesday is review and ungraded quiz Remember midterm on Friday! Post-HW2 midterm material questions today Sample midterm tomorrow

Arrays

Arrays are convenient ways to store similar data types Much like how we have been thinking of Strings as a list of characters Arrays are also indexed starting from zero

Arrays - declare/initialization

When making an array, you need both a type and a length. The format for making an array is below: Type, [] means array variable name length of array

Arrays - manual initialization

Arrays can be initialized by the following: If you try an access an array element that has not been initialized, your program will crash Arrays have a .length variable (similar to Strings) (See: ArrayPrintf.java)

Arrays

A char array is not a String While the important data in String is a char array, classes have methods unlike arrays More examples: (See: ArrayAverage.java) (See: Fibonacci.java)