Java array, vector, and string

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.