废话不多说了,直接给大家贴代码了。
具体代码如下所示:
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;}}
新闻热点
疑难解答