集册 Java实例教程 字符串以任何可迭代开头

字符串以任何可迭代开头

欢马劈雪     最近更新时间:2020-01-02 10:19:05

586
字符串以任何Iterable开头
// 来自 N o w J a v a . c o m - 时代Java


//package com.nowjava;


public class Main {

    /**

     * @param stringList iterable of possible starting words

     * @param str String to be examined

     * @return true if str starts with any of the Strings in startArray, false otherwise.

     */

    public static boolean startsWithAny(Iterable<String> stringList,

            String str) {

        return getStartingIndex(stringList, str) != -1;

    }


    /**

     * @param stringList iterable of possible starting words

     * @param examinedString String to be examined 

     * @return index of first matching element in startArray if matched, -1 otherwise

     */

    public static int getStartingIndex(Iterable<String> stringList,

            String examinedString) {

        int i = 0;

        for (String string : stringList) {

            
展开阅读全文