Here you can find the source of endsWith(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
ends or -1
public static int endsWith(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:/*from w ww.j a v a 2s.co m*/ * IBM Corporation - initial API and implementation *******************************************************************************/ public class Main { /** * Returns the index of the longest search string with which the given text ends 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> ends or <code>-1</code> */ public static int endsWith(String[] searchStrings, String text) { int index = -1; for (int i = 0; i < searchStrings.length; i++) { if (text.endsWith(searchStrings[i])) { if (index == -1 || searchStrings[i].length() > searchStrings[index].length()) index = i; } } return index; } }