Java String Capitalize All capitalizeAll(String string)

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

Description

First-letter capitalizes a string.

License

Open Source License

Declaration

public static String capitalizeAll(String string) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w w w  . jav a2s  .  c om*/
     * First-letter capitalizes a string.
     *
     * <pre> "HELLO" -> "Hello" or "hi it's me" -> "Hi It's Me" </pre>
     */
    public static String capitalizeAll(String string) {
        String[] tokens = string.split(" ");

        StringBuilder stringBuilder = new StringBuilder();
        for (String token : tokens) {
            stringBuilder.append(token.substring(0, 1).toUpperCase());
            stringBuilder.append(token.substring(1).toLowerCase());
            stringBuilder.append(" ");
        }
        // delete the trailing space, if it's there
        if (stringBuilder.length() > 0) {
            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
        }
        return stringBuilder.toString();
    }
}

Related

  1. capitaliseAll(String str)
  2. capitaliseAllWords(String str)
  3. capitaliseAllWords(String str)
  4. capitaliseAllWords(String str)
  5. capitalizeAll(final String value)
  6. capitalizeAll(String text)
  7. capitalizeAllFirstChar(String text)
  8. capitalizeAllWords(String text)
  9. capitalizeAllWords(String words)