【发布时间】:2021-12-23 01:44:15
【问题描述】:
这是我的方法,它返回字符串值列表,如下所示:10x2021
这是我发送给我的方法的值。
List<HistoryItem> historyItems = Arrays.asList
(
new HistoryItem(364, "10x2021", Long.valueOf("009"))
);
public static List<String> foo(List<HistoryItem> historyItems) {
List<HistoryItem> collect = historyItems.stream().filter(item -> item.getCreditStatus().equals(Long.valueOf("009")) || item.getCreditStatus().equals(Long.valueOf("0010")))
.collect(Collectors.toList());
List<String> reportingPeriods = new ArrayList<>();
for (HistoryItem historyItem : historyItems) {
reportingPeriods.add(historyItem.getReportingPeriod());
}
return reportingPeriods;
}
我想要做的是我希望输出看起来像 2021-10 , 2021-9, not 10x2021 。我不能完全按照我的意愿使用字符串的方法。如何解决这个问题?
【问题讨论】:
-
您能否将其简化为具体问题。你想把
10x2021变成2021-10吗?这可以通过正则表达式或 String.split 来完成 -
是的。我想转一下,最后加个逗号。
标签: java string methods split output