Java Collection Remove getItemsStartingWith(Collection items, String prefix, boolean removePrefix)

Here you can find the source of getItemsStartingWith(Collection items, String prefix, boolean removePrefix)

Description

get Items Starting With

License

Apache License

Declaration

public static List<String> getItemsStartingWith(Collection<String> items, String prefix, boolean removePrefix) 

Method Source Code

//package com.java2s;
/**//w  w w. j a v  a2s .  c  o  m
 * Copyright ? 2013 - 2017 WaveMaker, Inc.
 *
 * 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;
import java.util.Collection;

import java.util.List;

public class Main {
    public static List<String> getItemsStartingWith(Collection<String> items, String prefix, boolean removePrefix) {
        List<String> rtn = new ArrayList<String>();
        for (String s : items) {
            if (s.startsWith(prefix)) {
                if (removePrefix) {
                    s = s.substring(prefix.length());
                }
                rtn.add(s);
            }
        }
        return rtn;
    }

    private static String substring(String s, int i, String substring, int direction) {
        if (direction >= 0) {
            return s.substring(i + substring.length());
        } else {
            return s.substring(0, i);
        }
    }
}

Related

  1. getRemovedItems(Collection oldValues, Collection newValues)
  2. minus(Collection primaryCollection, Collection toBeRemovedCollection, Collection target)
  3. remove(Collection c, Object o)
  4. remove(Collection collection, Object object)