String遍历
使用for循环遍历String数组,可以使用以下代码:
String[] array = {"Hello", "World", "Java"};
for (String element : array) {
System.out.println(element);
}
这将逐个打印出数组中的每个元素:
Hello
World
Java
另一种遍历String数组的方式是使用普通for循环:
String[] array = {"Hello", "World", "Java"};
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
这将产生与上述相同的输出结果。
原文地址: https://www.cveoy.top/t/topic/iF35 著作权归作者所有。请勿转载和采集!