You could use commons lang's ArrayUtils.

array = ArrayUtils.removeElement(array, element)

commons.apache.org library:Javadocs

Answer from Peter Lawrey on Stack Overflow
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ java-remove-array-elements
Java Remove Array Elements: Methods and Examples | DigitalOcean
May 2, 2025 - To avoid shifting elements manually in Java, you can use System.arraycopy() to copy elements from the original array to a new array, effectively removing the element without manual shifting.
Discussions

How can i remove an element from array in Java - Stack Overflow
Hello everyone i am trying to remove an name that the user has put in from an String Array, i am new to programming and i have tried this but it doesn't work. Can someone help me or tell me what i am More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - How to remove unused elements from an array without the use of the Collections - Stack Overflow
I had an array of elements that I have converted in a String. But this String keeps again the empty elements of the array and I can't compare it with another String. How can I delete the empty ele... More on stackoverflow.com
๐ŸŒ stackoverflow.com
September 15, 2017
[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
[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
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 57254195 โ€บ how-can-i-remove-an-element-of-array-without-using-list-or-collection-methods
java - How can I remove an element of array without using list or collection methods - Stack Overflow
public void remove(int indexToRemove){ this.array[indexToRemove] = null; } I would not recommend this solution, since you practically do not remove any element from the array, you just override it with null;
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_arraylist_remove.asp
Java ArrayList remove() Method
If a value is specified and multiple elements in the list have the same value then only the first one is deleted. If the list contains integers and you want to delete an integer based on its value you will need to pass an Integer object. See More Examples below for an example. ... T refers to the data type of items in the list. 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); } }
๐ŸŒ
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. This is the reason Collection classes like ArrayList and HashSet ...
๐ŸŒ
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 - Answer: Duplicate elements from an array can be removed by using a temporary array that will count the elements one by one and only put the unique elements in the temporary array.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ remove-element-from-an-array-in-java
Remove Element from an Array in Java
December 16, 2021 - In this tutorial, we'll showcase examples of how to remove an element from an array in Java using two arrays, ArrayUtils.remove(), a for loop and System.arraycopy().
Find elsewhere
๐ŸŒ
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 from an array, when modifying small or mid-sized arrays.
๐ŸŒ
Netjstech
netjstech.com โ€บ 2017 โ€บ 07 โ€บ how-to-remove-elements-from-array-java.html
How to Remove Elements From an Array Java Program | Tech Tutorials
Java program to delete elements from an array without using any third party jar or Collection. Removing elements from an array using Apache Commons ArrayUtils class.
๐ŸŒ
CodeProject
codeproject.com โ€บ Questions โ€บ 5368786 โ€บ Remove-element-from-array-in-java
https://www.codeproject.com/Questions/5368786/Remo...
Do not try and find the page. Thatโ€™s impossible. Instead only try to realise the truth - For those who code; Updated: 1 Jul 2007
๐ŸŒ
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 ...
๐ŸŒ
javaspring
javaspring.net โ€บ blog โ€บ removing-an-element-from-an-array-java
How to Remove an Element from an Array in Java: Fast and Clean Methods Explained โ€” javaspring.net
Cons: Still requires manual index validation, not as readable as ArrayList for beginners. Java 8 introduced streams, which provide a declarative way to process collections. You can filter out elements and collect the result into a new array.
Top answer
1 of 2
2

There are no "empty" elements in an array, and you can't resize arrays either. All you can do is to put all of the elements you're interested in at one end of the array (e.g. starting at zero) with no "uninteresting" elements between them, and then construct a string from a portion of the array.

Use another variable to store the index of the next "empty" element in the array: every time you find a letter, increment this variable. Once you've finished iterating letters, this variable will contain the length of the array to use to create the string.

    char[] copyLoop = new char[26];
    int dst = 0;
    for (int i = 0; i < letters.length; i++) {
        if (letters[i] > 1) {
            char c = (char) (i + 97);
            copyLoop[dst++] = c;       
        }
    }
    return new String(copyLoop, 0, dst);

Or, of course, use a StringBuilder (which is doing effectively the same internally):

    StringBuilder copyLoop = new StringBuilder(26);
    for (int i = 0; i < letters.length; i++) {
        if (letters[i] > 1) {
            char c = (char) (i + 97);
            copyLoop.append(c);       
        }
    }
    return copyLoop.toString();
2 of 2
0

Unfortunately not. Arrays in Java are not shrinkable/expandable, their size is set constant. There are two ways you can work around:

  1. Use Collections, i.e. create a List of Characters ArrayList<Character> list = new ArrayList<>();, use it and delete items you don't need after each loop cycle.

  2. On every cycle of your for loop, when you need to delete an item inside your Array, just create a new char[] array, which is smaller and copy the contents of the old one to the new, except for the value you deleted.

Also, if you are working with Strings, it's recommended to use mutable String classes s.a. StringBuilder or StringBuffer which let you add/remove characters from the String. In your case that seems to be the best solution.

๐ŸŒ
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.
๐ŸŒ
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...
๐ŸŒ
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
๐ŸŒ
w3resource
w3resource.com โ€บ java-exercises โ€บ array โ€บ java-array-exercise-7.php
Java - Remove a specific element from an array
May 9, 2025 - int removeIndex = 1; // Loop to remove the element at the specified index. for (int i = removeIndex; i < my_array.length - 1; i++) { my_array[i] = my_array[i + 1]; } // Print the modified array after removing the second element.