易截截图软件、单文件、免安装、纯绿色、仅160KB

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());
  }
 }
 
}


相关文档:

Java中集合容器类List和Set的用法

List的用法
List包括List接口以及List接口的所有实现类。因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以List接口还提供了一些适合于自身的常用方法,如表1所示。
表1  List接口定义的常用方法及功能
从表1可以看出,List接口提供的适合于自身的 ......

Java 线程编程中的同步、重复、定时

(一)线程同步
实现生产者消费者问题来说明线程问题,举例如下所示:
/**
* 生产者消费者问题
*/
public class ProducerConsumer {

/**
* 主方法
*/
public static void main(String[] args) {
ProductBox pb = new ProductBox ......

java:double类型截取俩位小数,不取舍,

public class Split{
 public static void main(String[] args){
       double pai = 3.14159;
        findTwo(pai);
  public static void findTwo(double value){
    System.out.println(new DecimalFormat("0.##"). ......

java:大数据文件写入,读取,分割,排序,合并

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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号