Java String Starts Wtih startsWith(String toTest, String[] possibilities)

Here you can find the source of startsWith(String toTest, String[] possibilities)

Description

Tests whether the given string starts with one of the strings in the array

License

Open Source License

Parameter

Parameter Description
toTest the string to test
possibilities the strings to test against

Declaration

public static boolean startsWith(String toTest, String[] possibilities) 

Method Source Code

//package com.java2s;
/*/*from   www. ja  va 2s  . co m*/
 * Ulm University DUCKS project
 * 
 * Author:      Elmar Schoch <elmar.schoch@uni-ulm.de>
 * 
 * (C) Copyright 2006, Ulm University, all rights reserved.
 * 
 * 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.
 * 
 */

public class Main {
    /**
     * Tests whether the given string starts with one of the strings in the
     * array
     * @param toTest the string to test
     * @param possibilities the strings to test against
     * @return
     */
    public static boolean startsWith(String toTest, String[] possibilities) {
        for (String p : possibilities) {
            if (toTest.startsWith(p)) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. startsWith(String string, char... ca)
  2. startsWith(String string, String prefix)
  3. startsWith(String string, StringBuffer prefix, int toffset)
  4. startsWith(String target, String... prefixes)
  5. startsWith(String text, String prefix, int toffset)
  6. startsWith(String value, String startsWith)
  7. startsWith(String[] array, String obj)
  8. startsWith(String[] beginningSegments, String[] testSegments)
  9. startsWith(String[] searchStrings, String text)