Java String Title Case toTitleCase(String original)

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

Description

to Title Case

License

Apache License

Declaration

public static String toTitleCase(String original) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String toTitleCase(String original) {
        String[] words = original.split(" ");
        for (int i = 0; i < words.length; i++) {
            words[i] = toInitialCap(words[i]);
        }// w ww  . ja va  2 s  .co m
        return join(words, " ");
    }

    public static String toInitialCap(String original) {
        if (original.trim().length() == 0)
            return "";
        return original.substring(0, 1).toUpperCase() + original.substring(1).toLowerCase();
    }

    public static String join(String[] text, String appendChar) {
        StringBuffer sentance = new StringBuffer();
        for (int i = 0; i < text.length; i++) {
            sentance.append(text[i]);
            if (i != text.length - 1)
                sentance.append(appendChar);
        }
        return sentance.toString();
    }

    public static String toString(String[] arrStrs) {
        StringBuffer strBuf = new StringBuffer();
        for (int i = 0; i < arrStrs.length; i++) {
            strBuf.append(arrStrs[i] + ", ");
        }
        return strBuf.toString();
    }
}

Related

  1. toTitleCase(String input)
  2. toTitleCase(String input, boolean eachWord)
  3. toTitleCase(String inputStr)
  4. toTitleCase(String name)
  5. toTitleCase(String original)
  6. toTitleCase(String s)
  7. toTitleCase(String s)
  8. toTitleCase(String sIn)
  9. toTitleCase(String str)