Programming Tips - Java: grab all occurances of a pattern in a String

Date: 2012sep21 Language: Java Q. Java: grab all occurances of a pattern in a String A. Do group(1) while find() gets hits. Like this:
// This pattern will find all Capitalized words Pattern pat = Pattern.compile("([A-Z]\w+)"); Matcher matcher = pat.matcher(my_subject_string); while (matcher.find()) { String hitWord = matcher.group(1); System.out.println("hit=" + hitWord); }