【发布时间】:2017-08-30 02:13:18
【问题描述】:
我正在开发 Spring 应用程序。我有一个LinkedHashMap<Integer, List<MyDTO>> 对象,在地图的值中(即List<MyDTO>)我有属性myDate 持有日期。我想迭代LinkedHashMap<Integer, List<MyDTO>> 并从List<MyDTO> myDate 属性中获取最早和最新的日期。
LinkedHashMap<Integer, List<MyDTO>> myResults = myService.getResultData(myDTO);
for (Map.Entry results : myResults.entrySet()) {
List<MyDTO> myDTOList = (List<MyDTO>) results.getValue();
//some business logic to process the list object, myDate property is in this myDTOList from which i need to get the oldest anad latest date.
}
以上是示例代码,我尝试迭代 Map(myResults) 并获取地图对象的值 List<MyDTO>。关于如何从存储在 List 对象 (myDTOList) 中的 myDate 属性中的日期中获取最旧和最新日期的任何建议?? ,
【问题讨论】:
-
有什么难度?你不知道如何遍历列表?如何比较日期?
-
您的 MyDTO 对象模型是什么?到现在为止,您尝试了哪些方法来获得最后一次和第一次约会?
-
@user7833845,您可以使用Date库的before和after进行比较,请查看下面的示例代码。
-
你试过什么?您的代码中唯一的东西是一个无用的
for循环,它什么都不做。