Java String Proper Case toProperCase(String s)

Here you can find the source of toProperCase(String s)

Description

Convert the String s to proper case.

License

Open Source License

Parameter

Parameter Description
s String

Return

String

Declaration

public static String toProperCase(String s) 

Method Source Code

//package com.java2s;
/*/*from  w ww . j  ava2  s.c om*/
 * Copyright (c) 2008-2011 Simon Ritchie.
 * All rights reserved. 
 * 
 * This program is free software: you can redistribute it and/or modify 
 * it under the terms of the GNU Lesser General Public License as published 
 * by the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this program.  If not, see http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Convert the String s to proper case.
     * 
     * @param s String
     * @return String
     */
    public static String toProperCase(String s) {
        StringBuilder sb = new StringBuilder();

        for (String f : s.split(" ")) {
            if (sb.length() > 0) {
                sb.append(" ");
            }
            sb.append(f.substring(0, 1).toUpperCase()).append(f.substring(1, f.length()).toLowerCase());
        }

        return sb.toString();
    }
}

Related

  1. toProperCase(final String s)
  2. toProperCase(final String string)
  3. toProperCase(String s)
  4. toProperCase(String s)
  5. toProperCase(String s)
  6. toProperCase(String text)