Java String Index Of getMatchingIndexes(final String source, final String match)

Here you can find the source of getMatchingIndexes(final String source, final String match)

Description

Returns a list containing all the indexes at which match occurs in source .

License

Open Source License

Parameter

Parameter Description
source the text in which to search for
match the text to search for in source

Return

a list of all the indexes at which match occurrs

Declaration

private static List<Integer> getMatchingIndexes(final String source, final String match) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*  w  w  w.j a va  2 s  .  c  o  m*/
     * Returns a list containing all the indexes at which {@code match} occurs in {@code source}.
     *
     * @param source
     *            the text in which to search for
     * @param match
     *            the text to search for in {@code source}
     * @return a list of all the indexes at which {@code match} occurrs
     */
    private static List<Integer> getMatchingIndexes(final String source, final String match) {
        final List<Integer> indexes = new ArrayList<Integer>();
        int index = ((source.indexOf(match) + match.length())) - 1;
        while (index >= 0) {
            while (source.charAt(index) != '{') {
                index++;
            }
            indexes.add(index);
            index = source.indexOf(match, index + 1);
        }
        return indexes;
    }
}

Related

  1. getIndexesOf(String word, String value)
  2. getIndexOfChar(String str, String start, String end)
  3. getIndexOrConstraintName(String command)
  4. getIndexString(T array, String indexPrefix, String separatorPrefix)
  5. getLowerBoundsOfAllStrings(int length, int seedIndex, int routeLength)
  6. getMergedLine(String lineOne, String lineTwo, int insertingIndex)
  7. getNewlineIndexes(String src)
  8. getOffspringStrings(int startIndex, String treeStr)
  9. getPDFEncodingIndex(String key)