码迷,mamicode.com
首页 > 编程语言 > 详细

【java】TreeSet

时间:2017-03-26 16:01:37      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:rgs   opened   class   his   void   nts   tag   etag   pack   

技术分享
 1 package com.tn.treeSet;
 2 
 3 public class Student {
 4     private String name;
 5     private int age;
 6     public Student(){}
 7     public Student(String name, int age) {
 8         super();
 9         this.name = name;
10         this.age = age;
11     }
12     public String getName() {
13         return name;
14     }
15     public void setName(String name) {
16         this.name = name;
17     }
18     public int getAge() {
19         return age;
20     }
21     public void setAge(int age) {
22         this.age = age;
23     }
24     @Override
25     public String toString() {
26         return "Student [name=" + name + "]";
27     }    
28 }
Student
技术分享
 1 package com.tn.treeSet;
 2 
 3 import java.util.TreeSet;
 4 
 5 public class TreeSetDemo {
 6     public static void main(String[] args){
 7         TreeSet<Student> students=new TreeSet<>();//后一个尖括号内可以省略类型
 8         Student student1=new Student("武松",30);
 9         Student student2=new Student("林冲",31);
10         Student student3=new Student("鲁智深",29);
11         students.add(student1);
12         students.add(student2);
13         students.add(student3);
14         System.out.println(students);
15     }
16 }
TreeSetDemo

 运行结果:

技术分享


 

【java】TreeSet

标签:rgs   opened   class   his   void   nts   tag   etag   pack   

原文地址:http://www.cnblogs.com/xiongjiawei/p/6623063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!