[英]remove all instances of item from the input array rather than just one
public static String[] remove(String[] symbols, String c)
{
for (int i = 0; i < symbols.length; i++)
{
if (symbols[i] == null ? c == null : symbols[i].equals(c))
{
String[] copy = new String[symbols.length-1];System.arraycopy(symbols, 0, copy, 0, i);
System.arraycopy(symbols, i+1, copy, i, symbols.length-i-1);
return copy;
}
}
return symbols;
}
当您从数组中删除时,您不希望i
增加。 您也不想在循环之后返回任何内容。
更换线路
return copy;
和
symbols = copy;
i--;
该行return copy;
如果您想继续删除元素,则没有任何意义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.