Java List Starts with startsWithAny(String s, List prefixes)

Here you can find the source of startsWithAny(String s, List prefixes)

Description

Tests whether a string starts with any of a list of strings.

License

Open Source License

Declaration

public static boolean startsWithAny(String s, List<String> prefixes) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2009 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 * //from  w  w w. j a  v  a 2 s.  c o  m
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/

import java.util.List;

public class Main {
    /**
     * Tests whether a string starts with any of a list of strings.
     */
    public static boolean startsWithAny(String s, List<String> prefixes) {
        int count = prefixes.size();
        for (int i = 0; i < count; ++i) {
            if (s.startsWith((String) prefixes.get(i))) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. startsWith(List left, List right, boolean equals)
  2. startsWith(List left, List right, boolean equals)
  3. startsWith(List list0, List list1)
  4. startsWith(List string, List prefix)
  5. startsWithWord(String aTarget, List aExpectWordList)