Here you can find the source of startsWith(String[] searchStrings, String text)
-1
if none matches.
Parameter | Description |
---|---|
searchStrings | the strings to search for |
text | the text to search |
searchStrings
of the longest string with which text
starts or -1
public static int startsWith(String[] searchStrings, String text)
//package com.java2s; /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * 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 * * Contributors:// w ww .j a v a 2 s.com * IBM Corporation - initial API and implementation *******************************************************************************/ public class Main { /** * Returns the index of the longest search string with which the given text starts or <code>-1</code> * if none matches. * * @param searchStrings the strings to search for * @param text the text to search * @return the index in <code>searchStrings</code> of the longest string with which <code>text</code> starts or <code>-1</code> */ public static int startsWith(String[] searchStrings, String text) { int index = -1; for (int i = 0; i < searchStrings.length; i++) { if (text.startsWith(searchStrings[i])) { if (index == -1 || searchStrings[i].length() > searchStrings[index].length()) index = i; } } return index; } }