Java List Remove removeMember(String[] list, String id)

Here you can find the source of removeMember(String[] list, String id)

Description

Remove all instances of the given id from the member list.

License

BSD License

Parameter

Parameter Description
list The current array
id The id to remove

Return

A new combined array.

Declaration

public static String[] removeMember(String[] list, String id) 

Method Source Code

//package com.java2s;
/**//  w w w  . j a  va  2s  .  c om
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */

import java.util.*;

public class Main {
    /**
     * Remove all instances of the given id from the member list.
     * 
     * @param list The current array
     * @param id The id to remove
     * @return A new combined array.
     */
    public static String[] removeMember(String[] list, String id) {
        // FIXME: this is terribly inefficient.
        List<String> newList = new ArrayList<String>(Arrays.asList(list));
        newList.remove(id);
        return newList.toArray(new String[newList.size()]);
    }
}

Related

  1. removeFromListMap(T key, U value, Map> map)
  2. removeIgnoreCase(List l, String s)
  3. removeIgnoreCase(String needle, List haystack)
  4. removeItems(List list, T... remove)
  5. removeList(List l)
  6. removeObject(List l, T o)
  7. removeObjectList(List list, V o)
  8. removeReference(List l, Object o)