Java Utililty Methods Array Remove

List of utility methods to do Array Remove

Description

The list of methods to do Array Remove are organized into topic(s).

Method

String[]removeByPrefix(String[] array, String prefix)
remove By Prefix
List<String> list = new ArrayList<String>();
for (int i = 0; i < array.length; i++) {
    String s = array[i];
    if (!s.startsWith(prefix)) {
        list.add(s);
return list.toArray(new String[list.size()]);
...
byte[]removeByteOrderMark(final byte[] input)
This method removes the Byte Order Mark (BOM) from an array of bytes.
if (input == null) {
    return null;
int skip = 0;
if (input.length >= 3 && (input[0] == (byte) 0xEF) && (input[1] == (byte) 0xBB)
        && (input[2] == (byte) 0xBF)) {
    skip = 3;
else if (input.length >= 2 && (input[0] == (byte) 0xFE) && (input[1] == (byte) 0xFF)) {
    skip = 2;
else if (input.length >= 4 && (input[0] == (byte) 0xFF) && (input[1] == (byte) 0xFE)
        && (input[2] != (byte) 0x00) && (input[3] != (byte) 0x00)) {
    skip = 2;
else if (input.length >= 4 && (input[0] == (byte) 0x00) && (input[1] == (byte) 0x00)
        && (input[2] == (byte) 0xFE) && (input[3] == (byte) 0xFF)) {
    skip = 4;
else if (input.length >= 4 && (input[0] == (byte) 0xFF) && (input[1] == (byte) 0xFE)
        && (input[2] == (byte) 0x00) && (input[3] == (byte) 0x00)) {
    skip = 4;
if (skip > 0) {
    return Arrays.copyOfRange(input, skip, input.length);
return input;
String[]removeCommonWords(String[] words)
Returns a new String array with some of the most common English words removed.
if (commonWordsMap == null) {
    synchronized (initLock) {
        if (commonWordsMap == null) {
            commonWordsMap = new HashMap();
            for (int i = 0; i < commonWords.length; i++) {
                commonWordsMap.put(commonWords[i], commonWords[i]);
ArrayList results = new ArrayList(words.length);
for (int i = 0; i < words.length; i++) {
    if (!commonWordsMap.containsKey(words[i])) {
        results.add(words[i]);
return (String[]) results.toArray(new String[results.size()]);
E[]removeElement(final E[] array, final int index)
remove Element
final List<E> list = new ArrayList<>(Arrays.asList(array));
list.remove(index);
return list.toArray((E[]) new Object[list.size()]);
Object[]removeElement(Object[] array, Object entryToRemove)
Removes element from an array.
if (array != null && entryToRemove != null) {
    List<Object> list = new ArrayList<Object>();
    for (Object entry : array) {
        if (entry == null || !entry.equals(entryToRemove)) {
            list.add(entry);
    return list.toArray();
...
String[]removeElement(String array[], String element, int occurrences)
Remove an element from array.
List<String> list = new ArrayList<String>();
if (array.length == 1) {
    return new String[0];
int removed = 0;
for (String s : array) {
    if (s.trim().toUpperCase().equals(element.trim().toUpperCase())) {
        removed++;
...
String[]removeElement(String[] array, String remove)
Remove the given element from the array.
if (array == null)
    return array;
if (remove == null)
    return array;
List<String> elements = new ArrayList<>(array.length);
for (String s : array) {
    if (s.equalsIgnoreCase(remove))
        continue;
...
String[]removeElement(String[] elements, String element)
remove Element
String[] oldElements = elements;
if (oldElements.length == 0)
    return oldElements;
String[] newNatures = new String[oldElements.length - 1];
int index = Arrays.binarySearch(oldElements, element);
System.arraycopy(oldElements, index + 1, newNatures, index, oldElements.length - 1 - index);
return newNatures;
T[]removeElement(T[] array, int i)
remove Element
if (i < 0)
    return array;
if (i == 0)
    return Arrays.copyOfRange(array, 1, array.length);
T[] result = Arrays.copyOfRange(array, 0, array.length - 1);
for (int j = i + 1; j < array.length; j++)
    result[j - 1] = array[j];
return result;
...
T[]removeElement(T[] array, T removeObject)
Removes a object to an existing array in Java.
List<T> result = new LinkedList<>();
for (T item : array) {
    if (!removeObject.equals(item)) {
        result.add(item);
return result.toArray(array);