BlogJava 联系 聚合 管理  

Blog Stats

News

 

蓝冰飞寒个人独立博客地址,www.uphenan.com

随笔档案

文章档案


蓝冰飞寒

用心去做每一件事情



import java.util.*;

public class CollectionTest1{

    Collection c1 = new ArrayList();
    Collection c2 = new HashSet();
    
    public CollectionTest1(){
    Student s = new Student("李四",25000);
    c1.add(s);
    c1.add("张三");
    c2.add("王武");
    c2.add(new Student("赵柳",30000));
    printCollection(c1);
    printCollection(c2);
    
    
    
    }
    
    public void printCollection(Collection d){
           System.out.println("-----------------");
           Iterator it = d.iterator();
           while(it.hasNext()){
           System.out.println(it.next());
           }
    
    }
    
    public static void main(String args[]){
    new CollectionTest1();
    
    }


}
class Student {
    public Student(String a,int b) {
       this.name = a;
       this.slary =b;
    }
   public String name;
    public int slary;
public String toString(){
  String s="Name  "+name+"\n"+"GongZI  "+slary;
  return s;
  
  }
}
Tags -
文章来源:http://www.tt-shopping.com/kevinlau/read.php/108.htm
posted on 2009-05-09 21:59 蓝冰飞寒 阅读(38) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: