java:ArrayList循环遍历的俩种方法使用
package collection;
import java.util.*;
public class NewArrayList {
public static void main(String[] args) {
List<Student> students = new ArrayList<Student>();
for (int i = 0; i < 6; i++) {
students.add(new Student("Happy"+i,"male"+i,20+i));
}
print(students);
print2(students);
}
//循环遍历①for
public static void print(List<Student> newList){
System.out.println("总数据:"+newList.size());
Student student;
for (int i = 0; i < newList.size(); i++) {
student = (Student)newList.get(i);
System.out.println(student.toString());
}
}
//循环遍历①Iterator
public static void print2(List<Student> newList){
System.out.println("总数据:"+newList.size());
Iterator<Student> iterator = newList.iterator();
Student student;
while (iterator.hasNext()){
student = (Student)iterator.next();
System.out.println(student.toString());
}
}
}
相关文档:
为什么说乱码是中国程序员无法避免的话题呢?这个首先要从编码机制上说起,大家都是中文和英文的编码格式不是一样,解码也是不一样的!如果中国的程序员不会遇到乱码,那么只有使用汉语编程。汉语编程是怎么回事我也不大清楚,应该是前年吧,我一朋友给我介绍汉语编程,怎么不错不错?当时因为学习忙没去关注这个,等我闲 ......
在java对oracle的操作中,日期字段是很头疼的事情,其实仔细研究一下也并不难掌握。
举个例子来说明:
表 book 中有name varchar2(20)//书籍名称,buydate Date //购买日期 两个字段。
已经创建了数据库连接Connection conn;
方法一、使用java.sql.Date实现比较简单的yyyy-mm-dd格式日期。
java.sql. ......
package arrays.compara;
import java.util.Arrays;
public class Student {
public static void main(String[] args) {
Stu[] stus = new Stu[]{
new Stu(156,34,"ad"),
new Stu(153,24,"cc"),
new Stu(126,37,"ab"),
......
package arrays.file;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
i ......
package arrays.file;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamRea ......