Java String Find getOccurenceIndices(String inSubject, String inOccurence)

Here you can find the source of getOccurenceIndices(String inSubject, String inOccurence)

Description

get Occurence Indices

License

Open Source License

Declaration

public static List<Integer> getOccurenceIndices(String inSubject, String inOccurence) 

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<Integer> getOccurenceIndices(String inSubject, String inOccurence) {

        if (inSubject == null || inOccurence == null) {

            return new ArrayList<Integer>(0);
        }//from  w  w  w .  j a v a 2 s  .  c o m

        final List<Integer> theOccurences = new ArrayList<Integer>();
        int theLastIndex = 0;

        while (inSubject.length() >= theLastIndex + inOccurence.length()) {

            theLastIndex = inSubject.indexOf(inOccurence, theLastIndex);

            if (theLastIndex < 0) {

                break;
            }

            theOccurences.add(theLastIndex);
            theLastIndex += inOccurence.length();
        }

        return theOccurences;
    }
}

Related

  1. findAllOccurrences(String str, String substr)
  2. findAllSubsequences(String str)
  3. findParam(String src, char patternFrom, char patternTo)
  4. findResourceBundle(String aBundleName, Locale locale)
  5. getAllOccurences(String str, char guess)
  6. getSearchTermOccurrences(final String searchTerm, final String content)
  7. indexOfOccurance(String s1, String s2, Integer i)
  8. multiFindBetween(String source, String pre, String post)