I swear I did this a while back and it worked. But I can't remember how I did it. I want to find the indexes of multiple words in a string. The code below only works for one word. I need a more eloquent solution for dealing with several.
import java.util.*;
public class test {
    public static List<List<Boolean>> work;
    public static void main (String[] args) {
        String test = "I'm trying to both extract and replaces. This that and the other";
        String word = "I'm";
        for (int i = -1; (i = test.indexOf(word, i + 1)) != -1; ) {
            System.out.println(i);
        }
    }
}
Let's say I wanted to find the index of “both” and “other.”
 
     
     
     
    