Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static String capitalizeWords(String s) { StringBuilder sb = new StringBuilder(); String[] words = s.split("\\s+"); for (int i = 0; i < words.length; i++) { String word = words[i]; if (word.length() > 0) { sb.append(Character.toUpperCase(word.charAt(0))); if (word.length() > 1) { sb.append(word.substring(1)); } } if (i < words.length - 1) { sb.append(" "); } } return sb.toString(); } }