Java array, vector, and string
•
Java provides arrays, vectors, and strings.
An array of ordered data. The array name and subscript uniquely determine the elements in the array. Data types can be classified into two types: Basic Data Type and reference data type.
Vectors are variable-length arrays that allow coexistence of different types of elements.
Java provides powerful processing capabilities for string processing. Two types of string classes are defined: string and stringbuffer.
I. Array
In Java, arrays are processed as an instance of the array class. Therefore, an array is created using the new operator.
•
Type identifier array name [];
Type identifier[]Array name;
Price = new double [100];
Price = new double [10*10];
Price = new double [N * 2]; // assume that N is a constant of a known value.
• In Java, arrays of reference types (also called object arrays) can be used ).
Stu = new student [10]; // allocate a bucket and create a student Array
Vector Overview:
Vector is a data structure similar to arrays and stored in sequence, but it has more powerful functions than arrays,
It is a variable-length array that allows different types of elements to coexist..
• Element: a single data stored in a vector, which must be of the reference type. For example, "China" is an element stored in vector object v.
Capacity: The maximum number of elements that can be saved in a vector. In the figure, the capacity of vector V is 7.
Capacityincrement: the capacity to be increased when the current capacity cannot meet the storage requirements.
Size: the number of elements in the vector. In the figure, the current size of vector V is 4. Index: the number of the bucket in the vector. in Java, the vector is the same as the array, and the first element starts from 0.
Student [] Stu; // defines an array of student types
In Java, arrays are also a class of objects and are derived classes of the object class. In Java, the element of the array starts from 0. An array is a set of ordered data. The array name and subscript uniquely identify an element in an array.