Java String Title Case toTitleCase(String inputStr)

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

Description

to Title Case

License

Open Source License

Declaration

public static String toTitleCase(String inputStr) 

Method Source Code

//package com.java2s;
/*/*ww  w. jav a2 s  . co  m*/
 * Copyright 2006-2007 Vision Tech Solutions,(pvt) Ltd. All Rights Reserved.
 * This software is the confidential and proprietary information of
 * Vision Tech Solutions. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into 
 * with Vision Tech Solutions.
 */

public class Main {
    public static String toTitleCase(String inputStr) {
        char[] chars = inputStr.trim().toLowerCase().toCharArray();
        boolean found = false;

        for (int i = 0; i < chars.length; i++) {
            if (!found && Character.isLetter(chars[i])) {
                chars[i] = Character.toUpperCase(chars[i]);
                found = true;
            } else if (Character.isWhitespace(chars[i])) {
                found = false;
            }

        }

        return String.valueOf(chars);
    }
}

Related

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