【java】TreeSet

來源:互聯網
上載者:User

標籤: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     @Override25     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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.