Here you can find the source of capitalise(String string)
Parameter | Description |
---|---|
string | The String. |
public static String capitalise(String string)
//package com.java2s; //License from project: Open Source License import java.util.StringJoiner; public class Main { /**//ww w. j a va 2 s .c o m * Returns a new string consisting of the characters in the specified String, with the first letter of each word * capitalised, and the rest lower-case. * * @param string The String. * @return The capitalised String. */ public static String capitalise(String string) { String[] words = string.split(" "); StringJoiner builder = new StringJoiner(" "); for (String word : words) { String capitalised = Character.toUpperCase(word.charAt(0)) + word.substring(1).toLowerCase(); builder.add(capitalised); } return builder.toString(); } }