Here you can find the source of removeFromArray(String[] fieldList, String exludeElement)
Parameter | Description |
---|---|
fieldList | fieldList |
exludeElement | exludeElement |
public static String[] removeFromArray(String[] fieldList, String exludeElement)
//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; } }