Java List Remove removeFromArray(String[] fieldList, String exludeElement)

Here you can find the source of removeFromArray(String[] fieldList, String exludeElement)

Description

For removing specified value from a array.

License

Apache License

Parameter

Parameter Description
fieldList fieldList
exludeElement exludeElement

Return

formated array.

Declaration

public static String[] removeFromArray(String[] fieldList, String exludeElement) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;

import java.util.List;

public class Main {
    /**/*www .  j av a  2  s .  c o m*/
     * For removing specified value from a array.
     * 
     * @param fieldList fieldList
     * @param exludeElement exludeElement
     * @return formated array.
     */
    public static String[] removeFromArray(String[] fieldList, String exludeElement) {
        String[] newList = new String[fieldList.length - 1];
        List<String> oldList = null;
        int j = 0;

        oldList = Arrays.asList(fieldList);
        if (!oldList.contains(exludeElement)) {
            return fieldList;
        }
        for (int i = 0; i < fieldList.length; i++) {
            if (!exludeElement.equals(fieldList[i])) {
                newList[j] = fieldList[i];
                j++;
            }
        }
        return newList;
    }

    /**
     * check is the String array contain an input String.
     * 
     * @param array input array
     * @param s input String
     * @return boolean
     */
    public static boolean contains(String[] array, String s) {
        return (indexOf(array, s) > -1);
    }

    /**
     * get the index for input String from array.
     * 
     * @param array array
     * @param s string
     * @return index
     */
    public static int indexOf(String[] array, String s) {
        for (int i = 0; i < array.length; i++) {
            if (s != null && s.equals(array[i]))
                return i;
        }
        return -1;
    }
}

Related

  1. removeEmptyStringsInList(List list)
  2. removeEmptyTags(List tags)
  3. removeEmptyValues(final List values)
  4. removeFrom(List col, int from)
  5. removeFrom(List list, T member)
  6. removeFromListByClass(final List list, final String className)
  7. removeFromListMap(T key, U value, Map> map)
  8. removeIgnoreCase(List l, String s)
  9. removeIgnoreCase(String needle, List haystack)