java基础 Foreach循环

it2022-05-08  22

java SE5 引入了一种新的更简洁的for语句用于数组和容器,即foreach语法,表示不必要创建int变量去对有访问构成的序列进行计数,foreach将自动的产生每一项。

任何一个数组的方法都可以使用foreach,例如:

public class ForEachString{ public static void main(String[] args){ foreach( char c : "Hello world".toCharArray( ) ) ; System.out.println( c + " "); } }

  输出结果 H e l l o   w o r l d 

 

转载于:https://www.cnblogs.com/duolaAbao/p/6531824.html


最新回复(0)