Home > Java > javaTutorial > body text

How to access and iterate java arrays

王林
Release: 2023-05-29 15:24:46
forward
605 people have browsed it

1. Array access

Array name [index], such as a[0], a[1]

Notes

Array indexing starts from 0.

The data type of the index is an integer. The value of the index and the length of the array always differ by 1.

2. Array iteration

(1) for loop

int [] b1 = new int []{1,2,3,4,5,6,7};
for(int i =0;i<b1.length;i++){
System.out.println(b1[i]);
}
Copy after login

(2) Enhanced for loop

int [] b1 = new int []{1,2,3,4,5,6,7};
for(数组元素的类型 临时变量名字 :数组的名字){
System.out.println(临时变量名字 );
}
Copy after login

What is Java

Java is an object-oriented programming language that can write desktop applications, Web applications, distributed systems and embedded system applications .

The above is the detailed content of How to access and iterate java arrays. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template