Java Number Min Value minIndexOfOneOf(String string, int start, String needles)

Here you can find the source of minIndexOfOneOf(String string, int start, String needles)

Description

Find the first occurrence of any character in needles in string from the position start on.

License

Open Source License

Parameter

Parameter Description
string String to scan.
start Position of first character to take into account.
needles Characters to scan for.

Return

The first occurrence of any element of needles or -1 if none was found.

Declaration

public static int minIndexOfOneOf(String string, int start, String needles) 

Method Source Code

//package com.java2s;
/*/* w w  w .j  av a2 s .c om*/
 * dmfs - http://dmfs.org/
 *
 * Copyright (C) 2012 Marten Gajda <marten@dmfs.org>
 *
 * 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 2 of the License,
 * or (at your option) any later version.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

public class Main {
    /**
     * Find the first occurrence of any character in needles in string from the position start on.
     * 
     * @param string
     *            {@link String} to scan.
     * 
     * @param start
     *            Position of first character to take into account.
     * 
     * @param needles
     *            Characters to scan for.
     * 
     * @return The first occurrence of any element of needles or {@code -1} if none was found.
     * 
     */
    public static int minIndexOfOneOf(String string, int start, String needles) {
        if (string == null || string.length() == 0) {
            return -1;
        }

        int len = string.length();

        while (start < len) {
            if (needles.indexOf(string.charAt(start)) >= 0) {
                return start;
            }
            ++start;
        }
        return -1;
    }
}

Related

  1. minimum(long a, long b, long c)
  2. minimumEditDistance(String target, String source)
  3. minIndent(int a, int b)
  4. minIndex(int a, int b)
  5. minIndex(int ix1, int ix2)
  6. minInt(double d)
  7. minInt(final Iterable numbers)
  8. minInt(float a, float b)
  9. minInt(int a, int b)