HashMap>

发布于 2024-12-25 05:13:40 字数 288 浏览 2 评论 0 原文

我制作一个图表,将我的电子邮件可视化。我希望能够收到某一天的电子邮件。

这是一种不好的存储方式吗?

HashMap<DateTime, ArrayList<Email>>

还是将日期转换为字符串然后使用 HashMap>

注意,日期添加时不带小时、分钟和秒,所以就像 例如,2010 年 6 月 7 日

I work on a graph where I visualize my emails. I want to be able to get the emails from a certain day.

Is this a bad way to store?

HashMap<DateTime, ArrayList<Email>>

Or is it better to convert the date to a string and then use HashMap<String, ArrayList<Email>>

Note, the dates are added without hours, minutes and seconds, so just like 06/07/2010 for example.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叶落知秋 2025-01-01 05:13:40

DateTime 已经正确定义了 equalshashcode 方法,因此使用它们作为 HashMap 中的键是完全可以的。首先将它们转换为字符串并没有什么好处。

但是,我建议,如果您只想存储年/月/日组件,那么您可能需要使用 LocalDate 而不是 DateTime

此外,您还可以考虑使用 TreeMap 而不是 HashMap,以便您的地图自动按日期排序。可能会很方便。

DateTime has properly defined equals and hashcode methods, so using those as the key in a HashMap is perfectly OK. There's not much to be gained by converting them to strings first.

I would suggest, however, that if you only want to store the year/month/day components, then you may want to use LocalDate instead of DateTime.

Additionally, you could also consider using TreeMap rather than HashMap, so that your map is automatically sorted by date. Might be handy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文