用foreach遍历集合和数组
来源:互联网 发布:软件架构设计 编辑:程序博客网 时间:2024/06/05 08:06
public class Test{
public static void main(String[] args) {
List<String> list = new ArrayList();
list.add("南京");
list.add("北京");
list.add("上海");
System.out.println("用foreach遍历集合:");
for(String string:list){
System.out.println(string);
}
String[] strs = new String[list.size()];
list.toArray(strs);
System.out.println("\n用foreach遍历数组");
for(String string:strs){
System.out.println(string);
}
}
public static void main(String[] args) {
List<String> list = new ArrayList();
list.add("南京");
list.add("北京");
list.add("上海");
System.out.println("用foreach遍历集合:");
for(String string:list){
System.out.println(string);
}
String[] strs = new String[list.size()];
list.toArray(strs);
System.out.println("\n用foreach遍历数组");
for(String string:strs){
System.out.println(string);
}
}
}
foreach是for循环遍历集合和数组的一种简写形式。
对于集合类数据的遍历,应使用foreach。
0 0
- 用foreach遍历集合和数组
- foreach循环遍历数组和集合
- foreach简化数组和集合的遍历
- foreach简化数组和集合的遍历
- foreach简化数组和集合的遍历
- foreach和section遍历数组
- 用foreach和Iterator遍历集合的方法
- 用foreach来遍历数组
- 测试迭代器和foreach来遍历集合
- 遍历数组和集合
- Java中foreach和for在循环遍历数组、集合方面的区别
- 三中遍历数组和集合的方法 for foreach iterator
- 利用foreach和section遍历数组元素
- 利用foreach和section遍历数组内容
- Java数组和foreach遍历循环
- javascript中forEach和map遍历数组
- 集合遍历 Iterator Foreach
- 用foreach对数组进行遍历
- Postman 编辑和发送Cookie
- Android Training - 适配不同的屏幕(Lesson 2 - 适配不同屏幕密度)
- 使用联邦(FEDERATION)访问远程的DB2数据库
- VC/MFC 使用jsoncpp解析json格式内容
- (一) 隔直电容分析
- 用foreach遍历集合和数组
- 百度地图系列04——自定义Marker
- 外挂
- (二) 一阶RC低通滤波器杂记
- Java web工程中获取系统精确时间(到秒级别)
- WaitForTargetFPS
- 给计算机系学生的建议
- 【Html】使用<pre>标签为你的网页加入大段代码
- #CocoaPods# 安装和常见问题