从String中删除重复项

Son*_*iya 2 java string

这是我的代码,

   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;
}
Run Code Online (Sandbox Code Playgroud)

我想从正在返回的字符串"date"中删除重复的条目.日期[]和月[]是静态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|
Run Code Online (Sandbox Code Playgroud)

我想要这个:

25-5|28-5|4-6|8-6|10-6|14-6|17-6|7-7|26-7| 
Run Code Online (Sandbox Code Playgroud)

dog*_*ane 8

而不是将日期连接到字符串,而是在Set循环记录时将日期添加到a .集不能包含重复项.

然后在方法结束时,遍历您的集合并构造一个字符串以返回.