标签:rgb system password c中 sys public code port jdb
1、在idea中定义一个User类
1 import lombok.Data; 2 3 @Data 4 public class User { 5 private long id; 6 private String userName; 7 private String password; 8 private String name; 9 }
2、存储User
2.1 第一种:数组存储
1 User[] user = new User[20]; 2 for (int i=0; i<user.length; ++i){ 3 user[i] = new User(); 4 }
2.2 第二种:集合存储
1 List<User> list = new ArrayList<User>(); 2 list.add(user);
3、遍历
3.1 数组,略
3.2 集合
1 第一种: 2 List<User> list = new ArrayList<User>(); 3 UserDao1 userDao1 = new UserDao1(); 4 list = userDao1.selectUserByAll(); 5 Iterator<User> it = list.iterator(); //list集合可以通过迭代器进行遍历 6 while (it.hasNext()){ 7 System.out.println(it.next()); 8 } 9 第二种: 10 List<User> list = new ArrayList<User>(); 11 UserDao1 userDao1 = new UserDao1(); 12 list = userDao1.selectUserByAll(); 13 for (User user:list){ 14 System.out.println(user); 15 } 16 第三种: 17 List<User> list = new ArrayList<User>(); 18 UserDao1 userDao1 = new UserDao1(); 19 list = userDao1.selectUserByAll(); 20 for (int i=0; i<list.size(); ++i){ 21 System.out.println(list.get(i)); 22 }
标签:rgb system password c中 sys public code port jdb
原文地址:https://www.cnblogs.com/hanfei123/p/14441794.html