If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Arrays made easy

Iím writing this tutorial with help from Java Second solutions by John Lewis and William Loftus, most of it is from me but a few of the definitions are from the book.

What an array does: An array is a way of indexing an holding a large sum of information that can be called, used and sorted.

Declaring and Initializing an array: for an array to work you need to initialize it to a certain constant for example int[] height = new int[11]; . This will create a 1 dimensional array that holds 11 spots for integers. Integer arrays can only hold numbers, string arrays can hold numbers and letters and words but you canít do addition with the string arrays.

Visualization:
1D array: A 1 dimensional array is an array thatís just one column and this is usually used for sorting simple information like sorting.

2D array: A 2 dimensional array is like an excel table you have x amount of columns and x amount of rows that can be pulled by going down the rows and the columns and putting information in those slots. for example int[] 2dheight = new int[5][11]; this will hold 55 spots that can be dedicated to integers. With the 5 rows and 11 columns. This is the most common array especially for passwords.

3D array: A 3 dimensional array can be thought of as a cube. With the first digit being a specific part like if you made a 3 d string array that holds world info like if you made an array string[] country = new string[10][5][11]; would allow you to go thru any part of the first like the 10 would be countries and then from there you could go to 5 regional provinces and like 11 cities.

ND array: Any array with N dimensions should be thought of a bunch of lesser arrays, like visualize a 4 d array just as a bunch of limited 3 dimensional arrays, if it helps visualize the arrays in space like a bunch of interconnected 3d arrays (or cubes if you will) connected by some common thread.

yeah, it's easyer to declare arrays in C++ but the java book I use has a good explination so I paraphrased it for the part on defining the array. You'd need to use a vector in java.
here's an example of a vector:

//jebus.java Author: zepherin
//help from Java Software Solutions 2nd edition by John Lewis and William Loftus
//this will help the undstanding of vectors
import java.util.Vector;
public class jebus
{
public static void main (String[] args)
{
Vector animal = new Vector(); //this is the intialize of the vector

You can still use plain arrays in java but declaration is slightly diffrent for single dimension arrays and much diffrent for multidimensionnal arrays as you have to re-declare arrays in each subscript of the first array...