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 class ProducerConsumer {
/**
* 主方法
*/
public static void main(String[] args) {
ProductBox pb = new ProductBox ......
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.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 };
& ......