Java String Capitalize capitalize(String in)

Here you can find the source of capitalize(String in)

Description

Capitalize the first letter of a text.

License

Open Source License

Declaration

public static String capitalize(String in) 

Method Source Code

//package com.java2s;
//    it under the terms of the GNU General Public License as published by

public class Main {
    /**/*  w  w  w.j  a  v a  2  s. c  o  m*/
     * Capitalize the first letter of a text. Example : capitalize("toto")
     * returns "Toto"
     */
    public static String capitalize(String in) {
        return capitalize(in, false);
    }

    /**
     * Capitalize all words in a text. Result is trimmed, and all sequences of
     * white characters are replaced by a regular space: " ".
     * 
     * @param in
     * @param all
     * @return "toto tata" gives "Toto Tata"
     */
    public static String capitalize(String in, boolean all) {
        if (in == null || in.equals(""))
            return in;
        if (!all)
            return in.substring(0, 1).toUpperCase() + in.substring(1);
        else {
            StringBuffer out = new StringBuffer("");
            for (String word : in.split("\\s+")) {
                out.append(" ").append(capitalize(word));
            }
            return out.toString().trim();
        }
    }
}

Related

  1. capitalize(String constraint)
  2. capitalize(String content)
  3. capitalize(String data)
  4. capitalize(String english)
  5. capitalize(String in)
  6. capitalize(String in)
  7. capitalize(String in)
  8. capitalize(String input)
  9. capitalize(String input)