Java Array Remove removeElementInStringArray(String[] array, int index)

Here you can find the source of removeElementInStringArray(String[] array, int index)

Description

Remove element element with index on array

License

Open Source License

Parameter

Parameter Description
array a parameter
index a parameter

Declaration

public static String[] removeElementInStringArray(String[] array, int index) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/*from w  w w . j a  v  a  2s . c  o  m*/
     * Remove element element with index on array
     * @param array
     * @param index
     * @return
     */
    public static String[] removeElementInStringArray(String[] array, int index) {
        List<String> result = new ArrayList<String>();
        for (int i = 0; i < array.length; i++) {
            if (i != index) {
                result.add(array[i]);
            }
        }
        if (result.size() < 1)
            return null;
        return result.toArray(new String[result.size()]);
    }
}

Related

  1. removeElement(String array[], String element, int occurrences)
  2. removeElement(String[] array, String remove)
  3. removeElement(String[] elements, String element)
  4. removeElement(T[] array, int i)
  5. removeElement(T[] array, T removeObject)
  6. removeEmpties(String[] array)
  7. removeEmtpyStrings(String[] strings)
  8. removeFirst(String[] args)
  9. removeFirst(String[] array)