I am trying to remove an element from an array using ArrayList. however I cannot seem to get it to work. I'm new to java. Here is the code what i do
package workspace;
import java.util.*;
import java.util.stream.*;
public class Worksapce{
private static Collection<Integer> returnarrayList;
static int[] arrayRemover(int[] myArray,int index) {
List<Integer>arrayList = IntStream.of(myArray) .boxed().collect(Collectors.toList());
arrayList.remove(2);
returnarrayList = null;
return returnarrayList.stream().mapToInt(Integer::intValue).toArray();
}
public static void main(String[] args) {
int myArray[]= {1,2,3,4};
int index=2;
myArray=arrayRemover(myArray,index);
System.out.println(Arrays.toString(myArray));
}
}
Here is the error showing
I want to remove an element from the array.I know there is'nt a direct method in java to remove an element from the array.But there are exist several indirect methods.There I'm trying to remove element using arraylist. I didnt get the result. What are the mistakes in it? What i need to change?