package com.example.demo;
import java.util.ArrayList;
import java.util.Arrays;
public class TestArray {
public static void main(String[] args) {
String[] s = new String[]{"1","2","3","4","5"};
sout(s);
new ArrayList<>(Arrays.asList(s)).remove("2");
System.out.println("------------------");
sout(s);
String[] s1 = new String[5];
System.out.println("~~~~~~~~~~~~~~~~");
sout(s1);
}
public static void ArrayRemove(Object[] os,Object o) {
int index = 0;
for (index = 0; index < os.length; index++) {
if(os[index].equals(o)){
break;
}
}
int movenum = os.length - index - 1 ;
System.arraycopy(os,index+1,os,index,movenum);
os[os.length-1]= null;
}
static void sout(String[] ss){
for (int i = 0; i < ss.length; i++) {
System.out.println(ss[i]);
}
}
}
|