Skip to content

程序员灯塔

Menu
  • Download
  • sitemap
  • 文章归档
  • 标签归档
  • 示例页面
Menu

java 自定义类重写compare方法 ,使用Collections.sort排序

Posted on 2017 年 7 月 27 日

public class Bean implements Comparable {

…

…

@Override
public int compareTo(Bean_oneExp o) {

if(this.timestamp != o.getTimestamp()){
return (int)(this.timestamp – o.getTimestamp());//按照timestamp 升序
}else{
return this.location – o.location;
}

}

Collections.sort(exp_lst); // list里放的Bean对象

近期文章

  • 技术网站
  • 世界,您好!
  • Git学习记录(learngitbranching.js.org)
  • 阿里职场潜规则
  • 寻找两个正序数组的中位数

近期评论

  1. 一位 WordPress 评论者 发表在 世界,您好!

归档

  • 2024 年 9 月
  • 2024 年 3 月
  • 2022 年 12 月
  • 2021 年 8 月
  • 2021 年 6 月
  • 2021 年 3 月
  • 2021 年 2 月
  • 2020 年 11 月
  • 2020 年 5 月
  • 2020 年 3 月
  • 2019 年 11 月
  • 2019 年 10 月
  • 2019 年 9 月
  • 2019 年 7 月
  • 2019 年 6 月
  • 2019 年 5 月
  • 2019 年 3 月
  • 2018 年 9 月
  • 2018 年 8 月
  • 2018 年 7 月
  • 2018 年 4 月
  • 2018 年 2 月
  • 2018 年 1 月
  • 2017 年 12 月
  • 2017 年 11 月
  • 2017 年 10 月
  • 2017 年 8 月
  • 2017 年 7 月

分类目录

  • 未分类
©2025 程序员灯塔 | Design: Newspaperly WordPress Theme