You could use commons lang's ArrayUtils.

array = ArrayUtils.removeElement(array, element)

commons.apache.org library:Javadocs

Answer from Peter Lawrey on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › remove-an-element-at-specific-index-from-an-array-in-java
Remove an Element at Specific Index from an Array in Java - GeeksforGeeks
July 11, 2025 - Explanation: This example includes finding the element at the specified index and then removing that element. The rest of the elements are copied into a new array. This would lead to an array of size one less than the original array. We can use Java 8 streams to remove element at specific index ...
Discussions

[java] How do I remove an element from an array?
You can't remove an element from an array. You can flag it and skip it (e.g., like you've done with your Integer.MIN_VALUE) but you can't remove it. You can resize the array, though, but this is expensive if you do it often. Or what's more useful is to use some sort of list where remove operations are permitted. More on reddit.com
🌐 r/learnprogramming
5
2
July 21, 2014
How do I remove objects from an array in Java? - Stack Overflow
What do I have to do to delete/remove all the strings/objects equal to "a" in the array? ... You can't resize an array in Java. I assume you don't want to just null the elements since that would be trivial. More on stackoverflow.com
🌐 stackoverflow.com
How to remove elements from an array?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
23
2
January 31, 2026
[Java] Inserting and deleting elements in an array
Can you tell us a little more about the concept you're not understanding ? (Creating an array? Inserting while looping? Maybe pass-by-reference or pass-by-value ?) edit: Happy cakeday mick5000x ! More on reddit.com
🌐 r/learnprogramming
28
11
January 11, 2013
🌐
Java67
java67.com › 2012 › 12 › how-to-remove-element-from-array-in-java-example.html
How to Remove an Element from Array in Java with Example | Java67
... There is no direct way to remove elements from an Array in Java. Though Array in Java objects, it doesn't provide any methods to add(), remove(), or search an element in Array.
🌐
Baeldung
baeldung.com › home › java › java array › removing an element from an array in java
Removing an Element from an Array in Java | Baeldung
June 12, 2024 - Usually, this approach creates a brand-new array and copies all the values except for the value being removed. We can use the Apache Commons Lang library to remove the given element of an array.
🌐
Software Testing Help
softwaretestinghelp.com › home › java › remove/delete an element from an array in java
Remove/Delete An Element From An Array In Java
April 1, 2025 - Using Java8 streams, we can delete an element from an array. In order to do this, first, the array is converted to a stream. Then the element at the specified index is deleted using the filter method of streams.
🌐
Stack Abuse
stackabuse.com › remove-element-from-an-array-in-java
Remove Element from an Array in Java
December 16, 2021 - Due to the nature of array's memory placement, it is simply impossible to remove the element directly. Instead, to "remove" any element, all subsequent elements need to be shifted backward by one place. This will create an illusion that a specific element was removed.
🌐
Codidact
software.codidact.com › posts › 289778
How do I remove an element from a Java array? - Software Development
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...
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-remove-array-elements
Java Remove Array Elements: Methods and Examples | DigitalOcean
May 2, 2025 - On the other hand, it makes it challenging to dynamically modify the array, such as removing elements, as the size of the array cannot be changed once it is created. Unlike some other programming languages, Java does not provide a built-in method to remove elements from an array.
🌐
Netjstech
netjstech.com › 2017 › 07 › how-to-remove-elements-from-array-java.html
How to Remove Elements From an Array Java Program | Tech Tutorials
Enter Element to be deleted : 5 Elements -- 1 2 12 7 3 8 Enter Element to be deleted : 8 Elements -- 1 2 5 12 7 3 · With copying the element to the new array problem of empty space is solved. If you can use Apache commons in your application then there is a utility class ArrayUtils that can be used to remove elements from an array. import java.util.Scanner; import org.apache.commons.lang3.ArrayUtils; public class ElemRemoval { public static void main(String[] args) { Scanner in = new Scanner(System.in); int[] intArr = {1, 2, 5, 12, 7, 3, 8}; System.out.print("Enter Element to be deleted : "); int elem = in.nextInt(); for(int i = 0; i < intArr.length; i++){ if(intArr[i] == elem){ // Using ArrayUtils intArr = ArrayUtils.remove(intArr, i); break; } } System.out.println("Elements -- " ); for(int i = 0; i < intArr.length; i++){ System.out.print(" " + intArr[i]); } } }
🌐
TutorialsPoint
tutorialspoint.com › java_data_structures › java_data_structures_remove_elements_from_array.htm
Remove Elements from Arrays
The ArrayUtils class provide remove() method to delete an element from an array. import java.util.Scanner; import org.apache.commons.lang3.ArrayUtils; public class RemovingElements { public static void main(String args[]) { Scanner sc = new ...
🌐
How to do in Java
howtodoinjava.com › home › java array › removing items from an array in java
Removing Items from an Array in Java
February 10, 2022 - If the array doesn’t contains such an element, no elements are removed from the array. Let us look at a few examples of how to use these APIs. Java program to remove an item at index position 5. Integer[] originalArray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; Integer[] reducedArray = ArrayUtils.remove(originalArray, 5); //[0, 1, 2, 3, 4, 6, 7, 8, 9]
🌐
W3Schools
w3schools.com › java › ref_arraylist_remove.asp
Java ArrayList remove() Method
Remove an integer from the list by position and by value: import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<Integer>(); list.add(5); list.add(8); list.add(9); list.add(1); list.remove(Integer.valueOf(1)); // Remove by object list.remove(1); // Remove by index System.out.println(list); } }
🌐
Medium
medium.com › @Roshan-jha › solving-the-remove-element-problem-in-java-1a9333a55193
Solving the “Remove Element” Problem in Java | by Roshan Jha | Medium
November 18, 2023 - One pointer is used to iterate through the array, while the other pointer keeps track of the current position where elements not equal to the specified value should be placed. Let’s take a look at the Java code to solve this problem: public class RemoveElement { public static int removeElement(int[] nums, int val) { int k = 0; // Initialize the variable to count elements not equal to val // Iterate through the array for (int i = 0; i < nums.length; i++) { // If the current element is not equal to val if (nums[i] != val) { // Move the element to the front of the array nums[k] = nums[i]; // In
🌐
Java Guides
javaguides.net › 2024 › 05 › java-remove-element-from-array.html
Java: Remove Element from Array
May 29, 2024 - This guide will cover different ways to remove an element from an array, including using loops, the System.arraycopy method, and converting the array to a list and back to an array. ... In Java, arrays are fixed-size data structures that store elements of the same type.
Top answer
1 of 16
116

[If you want some ready-to-use code, please scroll to my "Edit3" (after the cut). The rest is here for posterity.]

To flesh out Dustman's idea:

List<String> list = new ArrayList<String>(Arrays.asList(array));
list.removeAll(Arrays.asList("a"));
array = list.toArray(array);

Edit: I'm now using Arrays.asList instead of Collections.singleton: singleton is limited to one entry, whereas the asList approach allows you to add other strings to filter out later: Arrays.asList("a", "b", "c").

Edit2: The above approach retains the same array (so the array is still the same length); the element after the last is set to null. If you want a new array sized exactly as required, use this instead:

array = list.toArray(new String[0]);

Edit3: If you use this code on a frequent basis in the same class, you may wish to consider adding this to your class:

private static final String[] EMPTY_STRING_ARRAY = new String[0];

Then the function becomes:

List<String> list = new ArrayList<>();
Collections.addAll(list, array);
list.removeAll(Arrays.asList("a"));
array = list.toArray(EMPTY_STRING_ARRAY);

This will then stop littering your heap with useless empty string arrays that would otherwise be newed each time your function is called.

cynicalman's suggestion (see comments) will also help with the heap littering, and for fairness I should mention it:

array = list.toArray(new String[list.size()]);

I prefer my approach, because it may be easier to get the explicit size wrong (e.g., calling size() on the wrong list).

2 of 16
33

An alternative in Java 8:

String[] filteredArray = Arrays.stream(array)
    .filter(e -> !e.equals(foo)).toArray(String[]::new);