排序日期方法中的投射异常 [英] Cast Exception in sorting date method

查看:19
本文介绍了排序日期方法中的投射异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表unSortedDateList",其中日期存储为 CSV.日期以以下格式存储 (MM/dd/yyyy)1/10/2012、2/10/2011、1/9/2011 *(注意:日期存储为逗号分隔值)*

I have a list "unSortedDateList" in which dates are stored as CSV. dates are stored in following format (MM/dd/yyyy) 1/10/2012, 2/10/2011, 1/9/2011 *(note: DATES ARE STORE as COMMA SEPERATED VALUE)*

我编写了一个函数,它从列表中获取这些日期并在 ASC 中对它们进行排序并存储在 sortedList 中.

I have written a function which takes these dates from the list and sort them in ASC and store in sortedList.

 TreeMap<Date, Date> sortedMap = new TreeMap<Date, Date>();

    for (Date theDate : unSortedDateList) 
    {
      sortedMap.put(theDate.getTime(), theDate);
    }
    List<Date> sortedList = (List<Date>) sortedMap.values();

程序抛出一个强制转换异常.

The program is throwing a cast exception.

你能帮我看看我做错了什么吗?

Can you please help me what i am doing wrong here?

推荐答案

为什么不使用

Collections.sort(unsortedDateList) 

直接?

这篇关于排序日期方法中的投射异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆