Home  >  Article  >  Java  >  How to reference java array elements

How to reference java array elements

WBOY
WBOYforward
2023-06-03 20:38:062536browse

Each element in the array can be referenced only after it is defined and allocated space with operator new. The reference method of array elements is:

(1) arrayName[index]

index is the subscript of the array element, which can make the integer always on or the integer expression. For example:

a[3], b[i], c[6*i];

(2) The subscript of array elements starts from 0; the legal subscript range of an array of length n is:

0~n -1;

Extension: Each array has an attribute lengthth (Note: length here is an attribute, not a method, and there are no parentheses (). We specifically explain it here to match the length of String. () method to make a distinction) specify its length, for example:

The value of a.length is the length of array a (number of elements)

Note:

public static void main(String args[]){}

us The main function in each class also has an array called srgs. So what is this array used for? This array is like injecting all in ipconfig -all on the command line. We can enter java TestArray (class name) 23,12, aa, bbb and several parameters. Then you can see it in the code output.

What are the advantages of Java

1. Simple. As long as you understand the basic concepts, you can write applications suitable for various situations;

2. Object-oriented ;

3. Distribution, Java is a network-oriented language;

4. Robustness, Java provides automatic garbage collection for memory management, preventing programmers from easily generating errors when managing memory. Error;

5. Security, Java used in network and distributed environments must prevent virus intrusion;

6. Architecture neutrality, as long as the Java runtime system is installed, Can run on any processor;

7. Portability, Java can be easily transplanted to different machines on the network;

8. Interpretation and execution, the Java interpreter directly interprets Java words Section code is interpreted and executed.

The above is the detailed content of How to reference java array elements. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete