Java Array Copy copyExcept(E[] orig, E excludedElem)

Here you can find the source of copyExcept(E[] orig, E excludedElem)

Description

Creates a List copy of orig, with all elements except elements equal to excludedElem.

License

Open Source License

Declaration

public static <E> List<E> copyExcept(E[] orig, E excludedElem) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007 DSource.org and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:// w w  w . ja  va 2 s  .co  m
 *     Bruno Medeiros - initial implementation
 *******************************************************************************/

import java.util.ArrayList;

import java.util.List;

public class Main {
    /** Creates a List copy of orig, with all elements except elements equal to excludedElem. */
    public static <E> List<E> copyExcept(E[] orig, E excludedElem) {
        List<E> rejectedElements = new ArrayList<E>(orig.length);

        for (int i = 0; i < orig.length; i++) {
            if (!orig[i].equals(excludedElem)) {
                rejectedElements.add(orig[i]);
            }
        }
        return rejectedElements;
    }
}

Related

  1. copyArrays(byte[] dest, byte[] source, int fromIdx)
  2. copyArrays(byte[] src, int srcOffset, byte[] dst, int dstOffset, int numBytes)
  3. copyArrayToStr(String[] src, String del)
  4. copyArrayWhenNotNull(byte[] source)
  5. copyBytes(byte[] data, int from, int to)
  6. copyIfExceeded(int[] arr, int len)
  7. copyIntoBigger(int[] array, int newSize, int defaultValue)
  8. copyOf(boolean[] t)
  9. copyOf(final U[] original, final int newLength, final Class newType)