Java String Capitalize capitalize(String s)

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

Description

capitalize

License

Open Source License

Declaration

public static String capitalize(String s) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 UCLA Medical Imaging Informatics Group
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 ******************************************************************************/

public class Main {
    public static String capitalize(String s) {

        // Capitalize only the first character of the string...

        if (s == null)
            return new String();

        switch (s.length()) {

        case 0://from   www.  j ava  2s .c om
            return new String();
        case 1:
            return s.toUpperCase();
        default:
            String lowerSubstring = s.substring(1).toLowerCase();
            String upperSubstring = s.substring(0, 1).toUpperCase();
            return new String(upperSubstring + lowerSubstring);
        }
    }
}

Related

  1. capitalize(String s)
  2. capitalize(String s)
  3. capitalize(String s)
  4. capitalize(String s)
  5. capitalize(String s)
  6. capitalize(String s)
  7. capitalize(String s)
  8. capitalize(String s)
  9. capitalize(String s)