-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNotes1028.txt
More file actions
42 lines (26 loc) · 912 Bytes
/
Notes1028.txt
File metadata and controls
42 lines (26 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Aim: How do we work with arrays?
Array
The simplest java data structure
A contiguous block of memory used to store multiple
values of the same type.
Arrays have a fixed size
An array can be re-initialized to a new size, but
that will erase all the data stored in it.
Each element in an array will contain the default value
for the array's data type until modified.
Array syntax basics:
int[] ray; //Array declaration
^
| Denote ray is an array of ints
ray = new int[10]; //Array initialization
^
| Sets the size of the array
ray.length; //Returns the size of the array
[]s are used to access values in an array.
ray[0] = 75;
ray[i] works, but 0 <= i < ray.length
Initializer lists
Used to create an array with preset values
char[] cray = { 'a', 'b', 'c' };
This will create a 3 character array with the
values 'a', 'b', and 'c'