遍历list集合的三种方式
List<String> list1 = new ArrayList<String>();
list1.add("1");
list1.add("2");
list1.add("3");
list1.add("4");
// 1、普通话for循环
String res = "";
for (int i = 0; i < list1.size(); i++) {
res += list1.get(i);
}
System.out.println(res);
// 2、增强for
String res2 = "";
for (String item : list1) {
res2 += item;
}
System.out.println(res2);
// 3、使用迭代器遍历
Iterator<String> it = list1.iterator();
String res3 = "";
while (it.hasNext()) {
res3 += it.next();
}
System.out.println(res3);
遍历list集合的三种方式的更多相关文章
- Java遍历List集合的三种方法
Java遍历List集合的三种方法 List<String> list = new ArrayList<String>(); list.add("aaa") ...
- java中遍历集合的三种方式
第一种遍历集合的方式:将集合变为数组 package com.lw.List; import java.util.ArrayList; import java.util.List; import ja ...
- Struts2-从值栈获取list集合数据(三种方式)
创建User封装数据类 public class User { private String username; private String password; public String getP ...
- 遍历Map集合的几种方式
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entr ...
- 遍历List集合的三种方法
List<String> list = new ArrayList<String>(); list.add("aaa"); list.add("b ...
- Java遍历List集合的4种方式
public class Test { public static void main(String[] args) { // 循环遍历List的4中方法 List<String> str ...
- Java修炼——ArrayList常用的方法以及三种方式遍历集合元素。
List接口ArrayList用法详解 ArrayList常用方法: 1. List.add():添加的方法(可以添加字符串,常量,以及对象) List list=new ArrayList(); l ...
- 遍历HashMap常用的的三种方式
遍历HashMap常用的的三种方式 HashMap是我们使用非常多的集合之一,下面就来介绍几种常用的HashMap的遍历方式. 1.首先定义一个新的HashMap,并往里面添加一些数据. HashMa ...
- ArrayList遍历的三种方式 array arrayList转换
ArrayList遍历的三种方式 - 呵呵静 - 博客园 https://www.cnblogs.com/mjyung/p/6725182.html
随机推荐
- hdu-5734 Acperience(数学)
题目链接: Acperience Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- Centos 5.x 升级 python2.7,安装setuptools、mysqldb 完整记录
最近由于有个工作任务需要搭个虚拟机环境,但是环境是搭建在内网,无法直接联网,很多软件都不能直接yum安装, 安装过程实在十分不顺利,在此留个记录给有需要的朋友. 环境是 CentOS 5.7 x6 ...
- [Codeforces 877E] Danil and a Part-time Job
[题目链接] https://codeforces.com/contest/877/problem/E [算法] 首先求出这棵树的DFS序 一棵子树的DFS序为连续的一段 , 根据这个性质 , 用线段 ...
- 是否要从单片机转为嵌入式Linux?
作者:嵌入式老鸟火哥 授权转载于公众号嵌入式老鸟的职场之道(ID: ict_embedded),有增加内容和修改. 最近很多童鞋投票并咨询如何从单片机转为嵌入式Linux开发.看来读者圈中做单片机,R ...
- hibernate学习三 精解Hibernate之核心文件
一 hibernate.cfg.xml详解 1 JDBC连接: 2 配置C3P0连接池: 3 配置JNDI数据源: 4 可选的配置属性: 5 hibernate二级缓存属性 6 hibernate事务 ...
- C - Present
C - Present Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit ...
- 20个Flutter实例视频教程-第05节: 酷炫的路由动画-1
视屏地址: https://www.bilibili.com/video/av39709290/?p=5 博客地址: https://jspang.com/post/flutterDemo.html# ...
- JavaScript 对象字面量
JavaScript 对象字面量 JavaScript 对象字面量 在编程语言中,字面量是一种表示值的记法.例如,"Hello, World!" 在许多语言中都表示一个字符串字 ...
- LeetCode: 557Reverse Words in a String III(easy)
题目: Given a string, you need to reverse the order of characters in each word within a sentence while ...
- HTML5 中的meter 标签的样式设置
meter { -webkit-appearance: none; position: relative; display: block; margin: 8px auto; width: 100px ...