Home  >  Article  >  Java  >  How to access and iterate java arrays

How to access and iterate java arrays

王林
王林forward
2023-05-29 15:24:46580browse

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]);
}

(2) Enhanced for loop

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

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!

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