Java StringJoiner Usage capitalise(String string)

Here you can find the source of capitalise(String string)

Description

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.

License

Open Source License

Parameter

Parameter Description
string The String.

Return

The capitalised String.

Declaration

public static String capitalise(String string) 

Method Source Code


//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();
    }
}

Related

  1. convertListToString(String[] stringList)
  2. generateDeleteCommand(int deleteDisplayIndex)
  3. getTraceString(StackTraceElement[] stackTraceElements)
  4. implode(T[] array, String delim)