62,616
社区成员
发帖
与我相关
我的任务
分享
return result.substring(0,result.length()-1);
import java.util.*;
public class Test1{
public static void main(String[] args){
String str="801;959;960;801;959;960;962";
String result=removeRepeated(str);
System.out.println(result);
}
public static String removeRepeated(String str){
String[] strs=str.split(";");
String result="";
HashSet<String> hs=new HashSet<String>();
for(String s:strs){
if(!hs.contains(s)){
result+=s+";";
hs.add(s);
}
}
return result.substring(0,result.length()-1);
}
}