In Java you can't delete elements from an array. But you can either:

Create a new char[] copying only the elements you want to keep; for this you could use System.arraycopy() or even simplerArrays.copyOfRange(). For example, for copying only the first three characters of an array:

char[] array1 = {'h','m','l','e','l','l'};
char[] array2 = Arrays.copyOfRange(array1, 0, 3);

Or use a List<Character>, which allows you to obtain a sublist with a range of elements:

List<Character> list1 = Arrays.asList('h','m','l','e','l','l');
List<Character> list2 = list1.subList(0, 3);
Answer from Óscar López on Stack Overflow
Discussions

java - Remove duplicate elements from char array - Code Review Stack Exchange
If input isn't limited to ASCII, ... but the array is faster. ... Emily L.Emily L. 16.7k11 gold badge3939 silver badges8989 bronze badges \$\endgroup\$ 3 · \$\begingroup\$ If we're assuming ASCII input, then 128 bools are sufficient. 256 are required for Latin-1 characters (and, obviously, 65536 for all the UTF-16 code-points a Java char can actually ... More on codereview.stackexchange.com
🌐 codereview.stackexchange.com
July 24, 2017
java - How to remove specific element from an array - Stack Overflow
I have tested different elements in a char array and if they do not meet the conditions I want to remove them from the array. Is there a way to do this? Here is my code sofar String s; char[]... More on stackoverflow.com
🌐 stackoverflow.com
July 31, 2012
java - Removing a character from an ArrayList of characters - Stack Overflow
I am facing with this unwanted char to int conversion in a loop. Say I have this List of Characters and I want to remove one of those: List chars = new ArrayList (); chars.... More on stackoverflow.com
🌐 stackoverflow.com
Removing an element from an Array (Java) - Stack Overflow
0 How to remove elements from an array in java even if we have to iterate over array or can we do it directly? 0 Java 8 or higher, removing values from char array More on stackoverflow.com
🌐 stackoverflow.com
🌐
Quora
quora.com › How-do-you-remove-a-character-from-a-char-array
How to remove a character from a char array - Quora
Answer (1 of 4): > How do you remove a character from a char array? You have “C” as one of the topics, so I’ll assume that’s what you’re referring to. The answer is likely to be very different for different languages. Basically, you don’t. Any array object has a size (number of elements) that’s...
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Remove element from an Array Java - Examples Java Code Geeks - 2026
July 6, 2022 - If everything goes well, the element present at index=2 will be removed from the specified array.To find out more about the best way to copy an array for each possible case you can check the Java Copy Array Example
🌐
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.
Top answer
1 of 3
3

One possibility is to use a Set. Just add the elements from the array and then get the unique elements from the Set. This algorithm will be O(n) instead of O(n^2) because each element is accessed only once.

Note that you can use Arrays.asList() to simplify the coding, too.

2 of 3
2

Here is a slightly convoluted algorithm that yields the same result as yours but is faster. It takes advantage of Java's native support for arrays instead of using an internal String:

private static char[] getYOURCharArray(char[] array) {
    char[] distinctChars = new char[0];
    char[] distinctCharsInOriginalOrder = new char[array.length];

    for (int i = 0; i < array.length; i++) {
        int binarySearchResult = Arrays.binarySearch(distinctChars, array[i]);

        if (binarySearchResult < 0) {
            char[] updatedDistinctChars = new char[distinctChars.length + 1];
            int insertionPointForNewChar = -(binarySearchResult + 1);

            System.arraycopy(distinctChars, 0, updatedDistinctChars, 0, insertionPointForNewChar);
            updatedDistinctChars[insertionPointForNewChar] = array[i];
            System.arraycopy(distinctChars, insertionPointForNewChar, updatedDistinctChars, insertionPointForNewChar + 1, distinctChars.length - insertionPointForNewChar);

            distinctChars = updatedDistinctChars;
            distinctCharsInOriginalOrder[distinctChars.length - 1] = array[i];
        }
    }

    return Arrays.copyOf(distinctCharsInOriginalOrder, distinctChars.length);
}

Using Arrays.binarySearch(char[], char) to look for a char in a char[] seems to be faster than searching for a char in a String using String.indexOf(int). On the other hand, Arrays.binarySearch(char[], char) requires the char[] to be sorted, which is why we need a second char[] that stores all distinct characters in the order they were first encountered in the original char[], assuming the returned char[] must fulfill this requirement (if it doesn't, then the array distinctCharsInOriginalOrder is actually not needed and you can return distinctChars directly at the end of this method, which might speed up the process a little bit). To ensure that distinctChars stays sorted, it is important to insert new chars at the correct position when updating distinctChars, which is why two calls to System.arraycopy are needed.

I did some simulations with random char arrays, each containing 100000 random characters. Here are the results of a set of 10 simulations:

With String: 9.183 seconds
With char arrays: 2.404 seconds

With String: 4.159 seconds
With char arrays: 2.075 seconds

With String: 4.721 seconds
With char arrays: 2.116 seconds

With String: 4.758 seconds
With char arrays: 2.056 seconds

With String: 4.517 seconds
With char arrays: 2.056 seconds

With String: 4.707 seconds
With char arrays: 2.038 seconds

With String: 4.803 seconds
With char arrays: 2.049 seconds

With String: 4.706 seconds
With char arrays: 2.024 seconds

With String: 4.683 seconds
With char arrays: 2.045 seconds

With String: 4.549 seconds
With char arrays: 2.052 seconds

I have no idea why the first simulation with the String algorithm takes twice as long as all the others. It was like that every time I ran the program, even when I switched the order of the two tests (meaning the first String algorithm still took twice as long as the others, even when the char[] algorithm was tested first). Maybe I did something wrong, or the JVM does something mysterious here.

Apparently, the larger the original char array, the greater the difference between the performance of the two algorithms. Here are the results of 10 simulations with 500000 random characters:

With String: 20.44 seconds
With char arrays: 4.474 seconds

With String: 21.344 seconds
With char arrays: 3.489 seconds

With String: 22.064 seconds
With char arrays: 3.315 seconds

With String: 22.155 seconds
With char arrays: 3.351 seconds

With String: 22.325 seconds
With char arrays: 3.386 seconds

With String: 22.149 seconds
With char arrays: 3.335 seconds

With String: 22.175 seconds
With char arrays: 3.352 seconds

With String: 22.16 seconds
With char arrays: 3.343 seconds

With String: 22.502 seconds
With char arrays: 3.362 seconds

With String: 22.122 seconds
With char arrays: 3.351 seconds
🌐
TutorialsPoint
tutorialspoint.com › javaexamples › string_removing_char.htm
How to Remove a Particular Character from a String in Java
The following example shows how to remove a particular character from a string using the StringBuilder Class · public class Main { public static void main(String args[]) { String str = "this is Java"; System.out.println(removeCharWithStringBuilder(str, 3)); // Removes character at index 3 } public static String removeCharWithStringBuilder(String s, int pos) { StringBuilder sb = new StringBuilder(s); // Creates a StringBuilder object sb.deleteCharAt(pos); // Deletes the character at the specified index return sb.toString(); // Converts StringBuilder back to String } }
Find elsewhere
🌐
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.
🌐
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 - Arrays have a fixed size, so creating a new array without the target element is often necessary. ... The basic approach to remove an element at a specific index is using a loop. ... // Java program to remove an element // from a specific index ...
🌐
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
When you remove an element from an array, you can fill the empty space with 0, space or null depending on whether it is a primitive array, string array or an Object array. Other alternative is to create a new array and copy the elements in that array. New array should have size of old array’s ...
🌐
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.
🌐
Stack Overflow
stackoverflow.com › questions › 32922606 › remove-caracteres-from-an-array
java - remove caracteres from an array - Stack Overflow
public void remove() { Button[] removeBtn = { (Button) findViewById(R.id.char1), (Button) findViewById(R.id.char2), (Button) findViewById(R.id.char3), (Button) findViewById(R.id.char4), (Button) findViewById(R.id.char5), (Button) findViewById(R.id.char6), (Button) findViewById(R.id.char7), (Button) findViewById(R.id.char8), (Button) findViewById(R.id.char9), (Button) findViewById(R.id.char10), (Button) findViewById(R.id.char11), (Button) findViewById(R.id.char12) }; for(int i=0;i<12;i++) { for(String s:_wd_array) { String str=removeBtn[i].getText().toString().toLowerCase(); if( !s.equals(str) ) { removeBtn[i].setBackgroundColor(Color.CYAN); removeBtn[i].getBackground().setAlpha(128); removeBtn[value].setVisibility(View.INVISIBLE); } } } } I compare the content of _wd_array with content of button,and if it's not equal I remove the button · Any pointers appreciated · Thanks · java ·
🌐
Java67
java67.com › 2023 › 11 › how-to-remove-given-character-from.html
How to remove given character from String using Recursion and Iteration in Java? Coding Interview Question | Java67
This iterative algorithm is very simple, but many programmer get confused by paying attention on remove() word and actually taking out character by doing expensive array copy operation. For example, they find index of first such character then create another String. Here is our complete Java program to remove a given character from a given String in Java.
🌐
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 ...