String regex replace using capture groups
Since Java SE 9, java.util.regex.Matcher
’s replaceAll()
method supports lambda expressions.
// import java.util.regex.*;
String varName = "random_string";
Pattern pattern = Pattern.compile("_([a-z])");
Matcher matcher = pattern.matcher(varName);
String result = matcher.replaceAll(m -> m.group(1).toUpperCase());
Source: Arvind Kumar Avinash’s answer on Stack Overflow
Check characters properties using Character
’s static methods
The Character
class provides some static predicates like
isAlphabetic(char c)
isDigit(char c)
isLowerCase(char c)
Source: Java Character isAlphabetic()
Method on Javapoint