java:Set循环遍历的俩种方法使用
package collection;
import java.util.*;
public class NewSet {
public static void main(String[] args) {
Set<Student> students = new HashSet<Student>();
for (int i = 0; i < 6; i++) {
students.add(new Student("Happy"+i,"male"+i,20+i));
}
students.add(new Student("Happy0","male0",20));
print(students);
print2(students);
}
//循环遍历①for
public static void print(Set<Student> newList){
System.out.println("总数据:"+newList.size());
/*Student student;
for (int i = 0; i < newList.size(); i++) {
student = (Student)newList
System.out.println(student.toString());
}*/
}
//循环遍历①Iterator
public static void print2(Set<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());
}
}
}
相关文档:
List的用法
List包括List接口以及List接口的所有实现类。因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以List接口还提供了一些适合于自身的常用方法,如表1所示。
表1 List接口定义的常用方法及功能
从表1可以看出,List接口提供的适合于自身的 ......
在java对oracle的操作中,日期字段是很头疼的事情,其实仔细研究一下也并不难掌握。
举个例子来说明:
表 book 中有name varchar2(20)//书籍名称,buydate Date //购买日期 两个字段。
已经创建了数据库连接Connection conn;
方法一、使用java.sql.Date实现比较简单的yyyy-mm-dd格式日期。
java.sql. ......
package arrays.myArray;
public class BinaryTree {
private Node root;
// 添加数据
public void add(int data) {
// 递归调用
if (null == root)
root = new Node(data, null, null);
else
addTree(root, data);
......
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" ......