这是我的密码
public static String set_x_dates()
{
int noRecords = GlobalData.getNoRecords();
int n;
String date = "";
if (noRecords <= 10)
for (n = 0; n < noRecords; n++)
date += Dates[n] + "-" + Month[n] + "|";
else {
for (n = 0; n < noRecords; n++) {
int gap = (int) (noRecords / 10);
date += Dates[n] + "-" + Month[n] + "|";
n++;
if (n != noRecords)
for (; gap > 0; gap--)
date += "|";
}
}
return date;
}
我希望从正在返回的字符串"date“中删除重复条目。Dates[]和Month[]是静态的int数组。有人能帮我吗?
我得到的输出是:
25-5|28-5|4-6|8-6|10-6|14-6|17-6|7-7|7-7|7-7|7-7|7-7|7-7|7-7|7-7|7-7|7-7|26-7|26-7|
我想要这个:
25-5|28-5|4-6|8-6|10-6|14-6|17-6|7-7|26-7|
发布于 2011-08-16 10:48:01
不要将日期连接到字符串中,而是在遍历记录时将日期添加到Set
中。集合不能包含重复项。
然后在方法的末尾,循环您的集合并构造一个字符串来返回。
发布于 2011-08-16 10:49:02
您可以组装一个字符串的设置,这些字符串将在填充集合后连接起来。
编辑:啊,dogbane是第一个到达的:P
发布于 2012-12-18 11:53:23
下面是删除字符串中重复项的代码。
产出:
https://stackoverflow.com/questions/7076927
复制相似问题