【发布时间】:2018-06-25 13:39:30
【问题描述】:
我有如下输入文件,input.txt
companyname,emailid,extenno,lastupdatedgmts
Dell,jcrshan@gmail.com,985553434,2018-06-13 23:30:52.12
Dell,jcrshan@gmail.com,85553434,2018-06-14 23:30:52.12
IBM,ramesh@gmail.com,785553434,2018-06-15 23:30:52.12
UTO,benny@gmail.com,785553434,2018-06-16 23:30:52.12
我想对上述输入文件执行以下操作,
1. sort the above file using emailed (second column) with ascending and lastupdatedgmts (fourth column) with descending
2.remove duplicate based on emailid (second column)
预期输出:
UTO,benny@gmail.com,785553434,2018-06-16 23:30:52.12
Dell,jcrshan@gmail.com,985553434,2018-06-14 23:30:52.12
IBM,ramesh@gmail.com,785553434,2018-06-15 23:30:52.12
你能帮忙吗?
【问题讨论】:
-
你在这里已经有一段时间了,所以应该知道如何钻研代码 - 你能发一个 minimal reproducible example 你到目前为止尝试过的东西吗?
-
是的将发布代码
-
为什么它同时标记为 java-8 和 java-7?它应该只标记您正在使用的版本
-
我对任何一个版本都很好。它会给你带来负担吗。
-
我会尝试的一个解决方案是将每一行插入一个二维列表。然后可以使用列表中的
Collections.sort()方法,使用自定义的Comparator。 see this for more details 在自定义比较器上。