Java String Starts Wtih startsWithOneOf(String source, boolean ignoreCase, String... values)

Here you can find the source of startsWithOneOf(String source, boolean ignoreCase, String... values)

Description

Determine whether the specified source string starts with one of the specified values.

License

Apache License

Parameter

Parameter Description
source the string to match with the values.
ignoreCase specifies whether case should be ignore in the string matching.
values the values to match the source with.

Return

true if the source matches one of the values, false otherwise.

Declaration

public static boolean startsWithOneOf(String source,
        boolean ignoreCase, String... values) 

Method Source Code

//package com.java2s;
/*//from  www.  ja va  2 s . co  m
 * JPPF.
 * Copyright (C) 2005-2010 JPPF Team.
 * http://www.jppf.org
 *
 * 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.
 */

public class Main {
    /**
     * Determine whether the specified source string starts with one of the specified values.
     * @param source the string to match with the values.
     * @param ignoreCase specifies whether case should be ignore in the string matching.
     * @param values the values to match the source with.
     * @return true if the source matches one of the values, false otherwise.
     */
    public static boolean startsWithOneOf(String source,
            boolean ignoreCase, String... values) {
        if ((source == null) || (values == null))
            return false;
        String s = ignoreCase ? source.toLowerCase() : source;
        for (String val : values) {
            if (val == null)
                continue;
            String s2 = ignoreCase ? val.toLowerCase() : val;
            if (s.startsWith(s2))
                return true;
        }
        return false;
    }
}

Related

  1. startsWithLowerCaseChar(String s)
  2. startsWithMultiple(String string, String... starts)
  3. startsWithName(String subject, String beginName)
  4. startsWithNoCase(String csValue, String csStart)
  5. startsWithOne(final String src, final String[] dest)
  6. startsWithOneOf(String str, String... strs)
  7. startsWithOneOf(String string, String... prefixes)
  8. startsWithOrMatches(String s1, String s2)
  9. startsWithPattern(String value, String matchingPatterns)