Java String Find findAll(final String s, final String subs)

Here you can find the source of findAll(final String s, final String subs)

Description

find All

License

Apache License

Declaration

public static int[] findAll(final String s, final String subs) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

public class Main {
    public static int[] findAll(final String s, final String subs) {
        if (s.length() == 0 || subs.length() == 0)
            return null;

        ArrayList<Integer> indices = new ArrayList<Integer>();
        int i = 0;
        int len = subs.length();

        int i0;// www  .  j  a v  a  2  s .com
        while ((i0 = s.substring(i, s.length()).indexOf(subs, i)) != -1) {
            indices.add(i0 + i);
            i += s.indexOf(subs, i) + len;
        }

        int[] r = new int[indices.size()];
        for (int n = 0; n < indices.size(); ++n)
            r[n] = indices.get(n);

        return r;
    }
}

Related

  1. findAll(String toSearch, String toFind, boolean ignoreCase)
  2. findAllIndexes(String str, String searchStr)
  3. findAllOccurences(String str, String pattern)
  4. findAllOccurrences(String str, String substr)