Java String Title Case toTitleCase(String givenString)

Here you can find the source of toTitleCase(String givenString)

Description

to Title Case

License

Open Source License

Declaration

public static String toTitleCase(String givenString) 

Method Source Code

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

public class Main {
    public static String toTitleCase(String givenString) {
        if (givenString.length() > 0) {
            String[] arr = givenString.split(" ");
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < arr.length; i++) {
                sb.append(Character.toUpperCase(arr[i].charAt(0)))
                        .append(arr[i].substring(1).toLowerCase())
                        .append(" ");
            }/*from   w w  w .  j a  v  a  2  s .  c o  m*/
            return sb.toString().trim();
        }
        return givenString;
    }
}

Related

  1. toTitleCase(final String input)
  2. toTitleCase(final String inStr)
  3. toTitleCase(final String inStr, final boolean putRestInLC)
  4. toTitleCase(final String s)
  5. toTitleCase(final String text)
  6. toTitleCase(String input)
  7. toTitleCase(String input, boolean eachWord)
  8. toTitleCase(String inputStr)
  9. toTitleCase(String name)