Java List IndexOf indexOf(final String regex, final List list)

Here you can find the source of indexOf(final String regex, final List list)

Description

Gets the index of the first occurrence of the given regex.

License

Open Source License

Parameter

Parameter Description
regex The regex to search for.
list The list that may contains the given regex.

Return

The index of the first occurrence. If not found, -1.

Declaration

public static int indexOf(final String regex, final List<String> list) 

Method Source Code

//package com.java2s;
/* This file is part of the InternalPluginManager.
 *
 * Copyright (C) 2014-2015 Fabian Damken
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.//from w w w  .  j  a va2  s .c  o m
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.List;

public class Main {
    /**
     * Gets the index of the first occurrence of the given regex.
     *
     * @param regex
     *            The regex to search for.
     * @param list
     *            The list that may contains the given regex.
     * @return The index of the first occurrence. If not found, <code>-1</code>.
     */
    public static int indexOf(final String regex, final List<String> list) {
        assert regex != null : "Regex cannot be null!";
        assert list != null : "List cannot be null!";

        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).matches(regex)) {
                return i;
            }
        }
        return -1;
    }
}

Related

  1. indexOf(int hash, List list)
  2. indexOf(int start, List datas, T target)
  3. indexOf(List list, Object element, int begin, int end)
  4. indexOf(List data, List token)