Here you can find the source of capitalizeWords(String s)
Parameter | Description |
---|---|
s | s |
public static String capitalizeWords(String s)
//package com.java2s; public class Main { /**//from ww w.j a v a2s.c om * capitalizeWords. * @param s s * @return String */ public static String capitalizeWords(String s) { if (s == null) { return null; } String[] tokens = s.split(" "); StringBuilder buf = new StringBuilder(); for (String x : tokens) { buf.append(capitalize(x) + " "); } return buf.substring(0, buf.length() - 1); } /** * capitalize. * @param s String * @return String */ public static String capitalize(String s) { if (isEmpty(s)) { return s; } return Character.toTitleCase(s.charAt(0)) + s.substring(1); } /** * whether or not the string is null or consists only of whitespace. * @param s * @return boolean * */ public static boolean isEmpty(String s) { return s == null || s.trim().length() == 0; } }