当前位置: 移动技术网 > IT编程>开发语言>Java > Java数组中的元素删除并实现向前移的代码

Java数组中的元素删除并实现向前移的代码

2019年07月22日  | 移动技术网IT编程  | 我要评论

考生志愿遭恶意篡改,南昌陆军学院,空间文

废话不多说了,直接给大家贴代码了。

具体代码如下所示:

public class test {
/**
* java怎么删除数组中的一个元素并且向前移
*
* @param args
* @throws ioexception
*/
public static void main(string[] args) {
string[] arrays = { "", "", "", "", "" };
system.out.println("数组删除前:");
for (int i = ; i < arrays.length; i++) {
system.out.print(arrays[i]+" ");
}
string[] arrays =removeitem(arrays,"");
system.out.println("");
system.out.println("数组删除后:");
for (int i = ; i < arrays.length; i++) {
system.out.print(arrays[i]+" ");
}
}
public static string[] removeitem(string[] arrays,string str){
string[] temparr = new string[arrays.length];
int i = ;
for(string s:arrays){
if(!s.equals(str)){
temparr[i] = s;
i++; 
}
}
return temparr;
}
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网