Java – Camel case verification of strings in android

Camel case verification of strings in android… here is a solution to the problem.

Camel case verification of strings in android


have a String test="The Mountain view", I need all characters after spaces in the string need to be capitalized, e.g. the above text 'M' is capitalized after spaces, and each character after spaces in String needs to reflect condition.

I need a

regular expression or condition to check if all characters after a space are uppercase, otherwise I need to change the string after a space to uppercase if it’s lowercase.

If anyone knows, it means help me.

Thank you.


Regular expressions are not required. Try this example, maybe it helps:

public class Capitalize {

public static String capitalize(String s) {
        if (s.length() == 0) return s;
        return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();

public static void main(String[] args) {
        while (! StdIn.isEmpty()) {
            String line = StdIn.readLine();
            String[] words = line.split("\\s");
            for (String s : words) {
                StdOut.print(capitalize(s) + " ");


Related Problems and Solutions