Introduction to Java object-oriented preparatory articles (3. Research arrays) Original: Array is a very important data structure, composed of data structures related to the same type of data is static entities, linked lists, queues, stacks, number and other data structures, Java also proposed Class of class vectors. These are part of the Java data structure. As we have learned, the data structure of the C language version, Java data structure is also to describe the data structure is just as Java. 1. Array It is important that the array subscript, array subscript and array name are used to provide visitors to provide access arrays, the data subscript starts from 0, C [0], is a first data first element is C [ I-1], the name rules of the array name are the same as the variable. It is also very simple to access the format: C.LENTH is the length of the array. C [A B] = 2 is the value of the array A B 2 In this array, there is also an easy place, that is, the seventh element and array element 7 of the array are two different concepts. The beginners must distinguish between differences. 2. Space allocation: Any data should take up space, An array is no exception. Java is used to assign a new array allocated space, an example: int C [] = new int [12]; its format is equivalent to int C []; c = new int tent [12]; their The initialization value is 0 an array to declare multiple array examples: string b [] = new string [100], x [] = new string [27]; arrays can declare any data type, Double String .. To analyze: // Fig. 7.5: InitaRray.java/INITIALIZE ARRAY N to the Even INTEGERS from 2 to 20import javax.swing. *;
Public Class INITARRAY {public static void main (string args []) {final int array_size = 10; int N []; // REFERENCE to int Array String Output = "
N = new int [array_size]; // allocate array
// set the values in the array for (INT i = 0; i Output = "subscript / TValue / n"; for (int i = 0; i Jtextarea Outputarea = New Jtextarea (11, 10); OutputArea.Settext (OUTPUT); JOPTIONPANE.SHOWMESSAGEDIALOG (NULL, OUTPUTAREA, "Initializing to Even Numbers from 2 to 20", JOPANE.INFORMATION_MESSAGE); System.exit (0);}} program: 1.Final Int Array_size = 10 Limit Word Final Declaration constant variable Array_Size its value is 10. 2. N = new int [array_size] declared that the length of N array does not exceed 10 3 .for (int i = 0; i Public class arraypass extends japplet {jTextarea outputarea; string output Public void init () {outputarea = new jtextarea (); container c = getContentPane (); C.ADD (Outputarea); INT A [] = {1, 2, 3, 4, 5}; output = "Effects of passing entire" "array call-by-reference: / n" "the value of the original array all: / n" ; For (int i = 0; i For (int i = 0; i The above is some of the basic concepts of arrays. And applications, plus the first 2 long articles, you have already learned about object-oriented basic concepts.