-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloArrays.java
More file actions
41 lines (26 loc) · 1.11 KB
/
HelloArrays.java
File metadata and controls
41 lines (26 loc) · 1.11 KB
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
class HelloArrays{
public static void main(String[] args){
//Arrays:
// Are a structure that store variables/values of the same type
// In Java, arrays are immutable. The size of the array cannot be changed.
// Arrays in Java are also objects, we have some methods that all Java Objects will have.
// We also have one extra property - .length
//To DECLARE an array:
//We DON'T declare size
//int myArray[];
int[] myArray; // Stick with this way of doing it
//Populating your array
//1) Directly populate it
//char[] myCharArray = {'a','b','c'};
//2) Create an empty array of fixed size
char[] myCharArray = new char[3];
myCharArray[0] = 'a'; //Arrays and all data structure in Java begin at 0
myCharArray[1] = 'b';
myCharArray[2] = 'c';
myCharArray[0] = '2';
myCharArray = new char[20]; //We are removing the old array and creating a brand new array.
System.out.println(myCharArray.length);
System.out.println(myCharArray.toString()); //convert an object into a string expression
(In the future, we are going to override this method to actually make it useful)
}
}