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());
}
}
}
相关文档:
package com.njty.util;
public class Test {
private static final double EARTH_RADIUS = 6378137;
private static double rad(double d)
{
return d * Math.PI / 180.0;
}
  ......
中国公历算法不是太难,关键是星期值的确定。这里给出了简单算法:
public static int dayOfWeek(int y, int m, int d) {
int w = 1; // 公历一年一月一日是星期一,所以起始值为星期日
y = (y-1)%400 + 1; //&n ......
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 arrays.myArray;
public class SortArr {
public static void main(String[] args) {
int[] arrInt = { 4, 7, 8, 5, 6, 3, 2, 3, 4 };
maoPaoSort(arrInt);
print("冒泡排序:", arrInt);
arrInt = new int[]{ 4, 7, 8, 5, 6, 3, 2, 3, 4 };
& ......
package arrays.myArray;
import java.util.Scanner;
public class SortObject {
private static int intercePosition = 0; // 记录单个运算数据的长度
private static int[] intercePositionIndex = null; // 记录“(”的下标
private static int[] intercePositionEnd = null; // 记录 ......