Java String Ends With endsWith(String[] searchStrings, String text)

Here you can find the source of endsWith(String[] searchStrings, String text)

Description

Returns the index of the longest search string with which the given text ends or -1 if none matches.

License

Open Source License

Parameter

Parameter Description
searchStrings the strings to search for
text the text to search

Return

the index in searchStrings of the longest string with which text ends or -1

Declaration

public static int endsWith(String[] searchStrings, String text) 

Method Source Code

//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;
    }
}

Related

  1. endsWith(String string, String... endsWithText)
  2. endsWith(String value, String[] suffixes)
  3. EndsWith(String x, String z)
  4. endsWith(String[] endsWith, String line)
  5. endsWith(String[] searchStrings, String text)
  6. endsWith(StringBuffer buf, String s)
  7. endsWith(StringBuffer buffer, String suffix)
  8. endsWith(StringBuffer in, String ending)
  9. endsWith(StringBuilder sb, String end)