import java.util.*; class TreeSetDemo{ public static void main(String[]args){ //TreeSet<String> ts = new TreeSet<String>(); Student ts = new Student("洪杰",21);//因为Student类中的构造方法有参数 /* ts.add("张三1",21); ts.add("张三2",22); ts.add("张三3",23); Iterator it = ts.iterator(); while(it.hasNext()){ System.out.println(it.next()); } */ System.out.println(ts); //该打印时对象 //该打印的是对象的属性 System.out.println("姓名:"+ts.getName()+",年龄:"+ts.getAge()); } } class Student{ private int age; private String name; Student(String name,int age){ this.name = name ; this.age = age; } public String getName(){ return name; } public int getAge(){ return age; } }
本文出自 “司马囧” 博客,转载请与作者联系!
原文:http://9274590.blog.51cto.com/9264590/1699729