Java tutorial
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { String str = "this is a test"; StringBuffer sb = new StringBuffer(); Matcher m = Pattern.compile("([a-z])([a-z]*)", Pattern.CASE_INSENSITIVE).matcher(str); while (m.find()) { m.appendReplacement(sb, m.group(1).toUpperCase() + m.group(2).toLowerCase()); } System.out.println(m.appendTail(sb).toString()); } } //This Is A Test