Here you can find the source of findAllOccurences(String str, String pattern)
Parameter | Description |
---|---|
str | a parameter |
pattern | a parameter |
public static ArrayList<Integer> findAllOccurences(String str, String pattern)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; public class Main { /**/* www.ja va2 s . co m*/ * Find all occurences (start positions) of pattern in string * @param str * @param pattern * @return a list of all matched positions (starts) */ public static ArrayList<Integer> findAllOccurences(String str, String pattern) { ArrayList<Integer> pos = new ArrayList<Integer>(); int len = pattern.length(); if (len > 0) { int start = str.indexOf(pattern); while (start != -1) { pos.add(start); start = str.indexOf(pattern, start + len); } } return pos; } }