Java: Main
Hello! I guess you are here cause you want to learn about the array basics in java. If that aint the case.. Your a confused/really stoned man..
Anyway, it might be a good idea to start with this tutorial now right? So, arrays, what are they? An array is a piece of code that lets you store many values in one place. Instead of declaring the values 1,2,3,4,5,6,7,8,9 and 0 in a variable each, you can use an array. To do so, you have to write in the code for the array. First you have to initialise the array with something like this:
int[] myArray;
myArray = new int[10];
the most of this part will be explained later..
Then the code for the array itself:
int[] myArray = {1,2,3,4,5,6,7,8,9,0};
Now im going to explain it as good as i can..
int[]
Tells the program that a certain thing (Like an array or a variable) is of the type int that can store numbers (Limited lenght). int for integer.
myArray
This is just the name of the array.
=
Its kinda obvious what this one does.. (Telling the program that the following will be assigned to the instance to the left.)
{1,2,3,4,5,6,7,8,9,0}
These are the values that are assigned to the array. each value is separated from others with the "," (comma). The curly brackets are just the begining and the end of the value/statement that is assigned to a function or something.. (In this case its values).
;
The semicolon is the end for the part of code that has it at the end. It tells the program that "Here is the end of this code, now start reading the next one.". Without the semicolon you will get an error since the program reads the line, then it continues to the next line that is something not relevant to the first.
Then we have the new int[10]
new is obvious, it tells that its something new :P . The int[10] gives the array myArray a max size of 10 values, all values after the first ten wont be accesible in the program.
To make it easier for you to understand arrays, heres some help:
First statement: The data type of the array, integer for example.
Second: the_name_of_the_array
Third: The position of the values in the array
0 first value
1 second value
2 third value
and so on..
The values are called "Data".
So, you want the whole code?? I wont give it to you :)
nah just kidding (lol :P ). Here it is:
int[] myArray;
myArray = new int[10];
int[] myArray = {1,2,3,4,5,6,7,8,9,0};
Thats it for the array basics, happy codeing everyone! :D