java basics @ mlab, 15-19 Nov 1999, juhuu@katastro.fi


arrays arrays (or lists or tables) are a way to handle bigger amounts of data. an array containing instances of a certain class is defined by Name_of_The_Class[] examples of syntax: // a String array called string_array String[] string_array; // reserve room for three instances of String class string_array = new String[3]; // the three places are now empty, let's fill them string_array[0] = "first"; string_array[1] = "second"; string_array[2] = "third"; // lets define another array and set the value at the same time String[] string_array2 = {"hii", "hoo", "haa", "huu"}; // lets define an integer array int[] integerlist = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // to go through all the values in the array, you can // use array.length // the indexes inside arrays start from 0! // so the list that contains three instances // has values array[0], array[1], array[2]) // print all the Strings in a string array for ( int i = 0 ; i < string_array.length ; i++) { System.out.println(string_array[i]); }