Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
One way to remove element from array is to replace element with zero. Below is a rough snippet I am sharing: int N = sc.nextInt(); int pos = sc.nextInt(); int A[] = new int[N]; if(pos == i) { ...
#2: Post edited
Remove element from array in java
- How do I remove an element from a Java array?
- One way to remove element from array is to replace element with zero. Below is a rough snippet I am sharing:
int N=sc.nextInt();int pos=sc.nextInt();int A[]=new int[N];if(pos==i){A[i]=0;- }
But the problem is that size of array remains same still. You have only replaced element with zero.What extra step we need to perform along with this?
- One way to remove element from array is to replace element with zero. Below is a rough snippet I am sharing:
- ```java
- int N = sc.nextInt();
- int pos = sc.nextInt();
- int A[] = new int[N];
- if(pos == i) {
- A[i]=0;
- }
- ```
- But the problem is that size of the array remains the same still. You have only replaced the element with zero.
- What extra steps we need to perform along with this?
#1: Initial revision
Remove element from array in java
One way to remove element from array is to replace element with zero. Below is a rough snippet I am sharing: int N=sc.nextInt(); int pos=sc.nextInt(); int A[]=new int[N]; if(pos==i) { A[i]=0; } But the problem is that size of array remains same still. You have only replaced element with zero. What extra step we need to perform along with this?