Regex replace space and word to toFirstUpper of word

Viewed 271

I was trying to use regex to change the following string

String input = "Creation of book orders" 

to

String output = "CreationOfBookOrders"

I tried the following expecting to replace the space and word with word.

input.replaceAll("\\s\\w", "(\\w)");
input.replaceAll("\\s\\w", "\\w");

but here the string is replacing space and word with character 'w' instead of the word.

I am in a position not to use any WordUtils or StringUtils or such Util classes. Else I could have replaced all spaces with empty string and applied WordUtils.capitalize or similar methods.

How else (preferably using regex) can I get the above output from input.

1 Answers
Related