Here you can find the source of removeFromArray(String remove, String array[])
Parameter | Description |
---|---|
remove | The element to be removed. |
array | The String array to remove the element from. |
public static String[] removeFromArray(String remove, String array[])
//package com.java2s; /*/* www . jav a 2s.co m*/ * Copyright 2015 The OpenDCT Authors. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; public class Main { /** * Remove every element that matches a string from an array. * * @param remove The element to be removed. * @param array The String array to remove the element from. * @return A new array. */ public static String[] removeFromArray(String remove, String array[]) { ArrayList<String> returnValues = new ArrayList<>(); for (String value : array) { if (!value.equals(remove)) { returnValues.add(value); } } return returnValues.toArray(new String[returnValues.size()]); } }