在Java中,可以使用for循环来遍历数组。以下是两种常用的遍历数组的方法:
int[] array = {1, 2, 3, 4, 5};
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
int[] array = {1, 2, 3, 4, 5};
for (int element : array) {
System.out.println(element);
}
以上两种方法都可以用来遍历数组,根据具体情况选择合适的方法。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:java中怎么使用foreach遍历数组