Java String Index Of getAllIndex(String source, String rex)

Here you can find the source of getAllIndex(String source, String rex)

Description

get All Index

License

Apache License

Declaration

public static int[] getAllIndex(String source, String rex) 

Method Source Code

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

import java.util.*;

public class Main {

    public static int[] getAllIndex(String source, String rex) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        int position = 0;
        while (position < source.length()) {
            int index = source.indexOf(rex, position);
            if (index > -1) {
                list.add(source.indexOf(rex, position));
                position = index + 1;/*w  ww  .j a va  2  s.  co m*/
            } else {
                break;
            }
        }

        int[] ins = new int[list.size()];
        for (int i = 0; i < ins.length; i++) {
            ins[i] = list.get(i);
        }

        return ins;
    }
}

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)