Java 怎么去掉字符串中的重复数据
Java怎么去掉字符串中的重复数据Stringa="06-104,07-104,06-104,07-104,03-103,04-103,03-103,04-103,05-...
Java 怎么去掉字符串中的重复数据String a="06-104,07-104,06-104,07-104,03-103,04-103,03-103,04-103,05-102,";
怎么去掉重复的,然后打印出来是
06-104,07-104,03-103,04-103,05-102 展开
怎么去掉重复的,然后打印出来是
06-104,07-104,03-103,04-103,05-102 展开
2个回答
展开全部
import java.util.*;
class This {
public static void main(String[] args) {
String a="06-104,07-104,06-104,07-104,03-103,04-103,03-103,04-103,05-102,";
a = a.replaceAll("^,*|,*$",",");
String reg = "(,[^,]+,).*\\1+";
while(a.matches("^.*" + reg + ".*$")){
a = a.replaceAll(reg,"$1");
}
a = a.replaceAll("^,+|,+$","");
System.out.println(a);
}
}
追问
正解!而且顺序不变
2017-07-22
展开全部
放在set数组里面
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询