Java Array Remove remove(boolean[] array, boolean value)

Here you can find the source of remove(boolean[] array, boolean value)

Description

remove

License

Open Source License

Declaration

public static boolean[] remove(boolean[] array, boolean value) 

Method Source Code

//package com.java2s;
/**// w  ww. j  a  va  2 s.co  m
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static boolean[] remove(boolean[] array, boolean value) {
        List<Boolean> list = new ArrayList<Boolean>();

        for (int i = 0; i < array.length; i++) {
            if (value != array[i]) {
                list.add(new Boolean(array[i]));
            }
        }

        return toArray(list.toArray(new Boolean[list.size()]));
    }

    public static byte[] remove(byte[] array, byte value) {
        List<Byte> list = new ArrayList<Byte>();

        for (int i = 0; i < array.length; i++) {
            if (value != array[i]) {
                list.add(new Byte(array[i]));
            }
        }

        return toArray(list.toArray(new Byte[list.size()]));
    }

    public static char[] remove(char[] array, char value) {
        List<Character> list = new ArrayList<Character>();

        for (int i = 0; i < array.length; i++) {
            if (value != array[i]) {
                list.add(new Character(array[i]));
            }
        }

        return toArray(list.toArray(new Character[list.size()]));
    }

    public static double[] remove(double[] array, double value) {
        List<Double> list = new ArrayList<Double>();

        for (int i = 0; i < array.length; i++) {
            if (value != array[i]) {
                list.add(new Double(array[i]));
            }
        }

        return toArray(list.toArray(new Double[list.size()]));
    }

    public static int[] remove(int[] array, int value) {
        List<Integer> list = new ArrayList<Integer>();

        for (int i = 0; i < array.length; i++) {
            if (value != array[i]) {
                list.add(new Integer(array[i]));
            }
        }

        return toArray(list.toArray(new Integer[list.size()]));
    }

    public static long[] remove(long[] array, long value) {
        List<Long> list = new ArrayList<Long>();

        for (int i = 0; i < array.length; i++) {
            if (value != array[i]) {
                list.add(new Long(array[i]));
            }
        }

        return toArray(list.toArray(new Long[list.size()]));
    }

    public static short[] remove(short[] array, short value) {
        List<Short> list = new ArrayList<Short>();

        for (int i = 0; i < array.length; i++) {
            if (value != array[i]) {
                list.add(new Short(array[i]));
            }
        }

        return toArray(list.toArray(new Short[list.size()]));
    }

    public static String[] remove(String[] array, String value) {
        List<String> list = new ArrayList<String>();

        for (String s : array) {
            if (!s.equals(value)) {
                list.add(s);
            }
        }

        return list.toArray(new String[list.size()]);
    }

    public static Boolean[] toArray(boolean[] array) {
        Boolean[] newArray = new Boolean[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = Boolean.valueOf(array[i]);
        }

        return newArray;
    }

    public static boolean[] toArray(Boolean[] array) {
        boolean[] newArray = new boolean[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = array[i].booleanValue();
        }

        return newArray;
    }

    public static Byte[] toArray(byte[] array) {
        Byte[] newArray = new Byte[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = Byte.valueOf(array[i]);
        }

        return newArray;
    }

    public static byte[] toArray(Byte[] array) {
        byte[] newArray = new byte[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = array[i].byteValue();
        }

        return newArray;
    }

    public static Character[] toArray(char[] array) {
        Character[] newArray = new Character[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = Character.valueOf(array[i]);
        }

        return newArray;
    }

    public static char[] toArray(Character[] array) {
        char[] newArray = new char[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = array[i].charValue();
        }

        return newArray;
    }

    public static Double[] toArray(double[] array) {
        Double[] newArray = new Double[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = new Double(array[i]);
        }

        return newArray;
    }

    public static double[] toArray(Double[] array) {
        double[] newArray = new double[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = array[i].doubleValue();
        }

        return newArray;
    }

    public static Float[] toArray(float[] array) {
        Float[] newArray = new Float[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = new Float(array[i]);
        }

        return newArray;
    }

    public static float[] toArray(Float[] array) {
        float[] newArray = new float[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = array[i].floatValue();
        }

        return newArray;
    }

    public static Integer[] toArray(int[] array) {
        Integer[] newArray = new Integer[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = new Integer(array[i]);
        }

        return newArray;
    }

    public static int[] toArray(Integer[] array) {
        int[] newArray = new int[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = array[i].intValue();
        }

        return newArray;
    }

    public static Long[] toArray(long[] array) {
        Long[] newArray = new Long[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = new Long(array[i]);
        }

        return newArray;
    }

    public static long[] toArray(Long[] array) {
        long[] newArray = new long[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = array[i].longValue();
        }

        return newArray;
    }

    public static Short[] toArray(short[] array) {
        Short[] newArray = new Short[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = new Short(array[i]);
        }

        return newArray;
    }

    public static short[] toArray(Short[] array) {
        short[] newArray = new short[array.length];

        for (int i = 0; i < array.length; i++) {
            newArray[i] = array[i].shortValue();
        }

        return newArray;
    }
}

Related

  1. remove(int[] a, int[] b)
  2. remove(String[] initial, String... toExclude)
  3. remove(String[] target, String[] needRemoved)
  4. remove(T[] a, int i)