Crow_Null 2015-12-19 03:59 采纳率: 100%
浏览 1743
已采纳

java 中的类可以被排序吗?

作业中有如下一步要求:
Add functionality to your classes that would allow them to be sorted by name with the Collections.sort method.

之后还要求输出
Create a method called print that would take your collection and list all of the contents. It should handle all of your classes. You should also demonstrate the Collections.sort method.

网上了解到collection是一个集合的接口, 那么class也可以作为一个集合? 向内部添加不同的classes并支持排序??
如果可以, 该如何创建一个class的集合呢?求教

  • 写回答

7条回答 默认 最新

  • 毕小宝 博客专家认证 2015-12-19 04:21
    关注

    对象可以排序,Java的集合工具类Collections.sort可以完成对集合的排序,如果集合中元素为对象,那么对象类型需要实现comparable接口。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?