不仅list是有序集合,set也可以变为有序集合。

/**
     * 给字符串时间的set排序
     * @return 有序的set集合
     */
    public static Set getSort(){
         Set<String> st = new TreeSet<String>(new Comparator()
    {
          public int compare(Object o1, Object o2) {
          String time1 = o1.toString();
          String time2 = o2.toString();
          if (DataFormat.stringToMillss(time1) > DataFormat.stringToMillss(time2))
        {
             return 1;
        }else if (DataFormat.stringToMillss(time1) == DataFormat.stringToMillss(time2))
        {
            return 0;
         } else{
            return -1;
            }
        }
    });    
        return st;
}
View Code

相关文章:

  • 2022-12-23
  • 2021-08-06
  • 2021-12-25
  • 2021-08-04
  • 2021-11-21
  • 2021-02-14
  • 2021-06-13
猜你喜欢
  • 2022-12-23
  • 2021-07-05
  • 2021-10-03
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
相关资源
相似解决方案