Java examples for Collection Framework:Iterable
String starts With Any Iterable
//package com.java2s; public class Main { /**/*w ww . j a v a 2 s. c om*/ * @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) { if (examinedString.startsWith(string)) { return i; } i++; } return -1; } }