描述
输入两个字符串,从第一字符串中删除第二个字符串中所有的字符
样例
输入: str=”They are students”,sub=”aeiou”
输出: ”Thy r stdnts”
public String deleteString (String str,String sub){
if(str.equals("")){
return str;
}
if(sub.equals("")){
return sub;
}
HashSet set = new HashSet();
for(int i=0;i<sub.length();i++){
set.add(sub.charAt(i));
}
StringBuilder builder = new StringBuilder();
for(int i=0;i<str.length();i++){
if(!set.contains(str.charAt(i))){
System.out.println(str.charAt(i));
builder.append(str.charAt(i));
}
}
return builder.toString();
}