Java String Capitalize capitalize(String source)

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

Description

Ensure that the first character of the provided string is upper case.

License

Apache License

Parameter

Parameter Description
source The <code>String</code> to capitalize.

Return

The capitalized String.

Declaration

public static String capitalize(String source) 

Method Source Code

//package com.java2s;
/*//from  w  w  w .jav  a  2  s.co m
 * Copyright 2001-2013 Geert Bevin (gbevin[remove] at uwyn dot com)
 * Licensed under the Apache License, Version 2.0 (the "License")
 */

public class Main {
    /**
     * Ensure that the first character of the provided string is upper case.
     *
     * @param source The <code>String</code> to capitalize.
     * @return The capitalized <code>String</code>.
     * @since 1.0
     */
    public static String capitalize(String source) {
        if (source == null || source.length() == 0) {
            return source;
        }

        if (source.length() > 1 && Character.isUpperCase(source.charAt(0))) {
            return source;
        }

        char chars[] = source.toCharArray();
        chars[0] = Character.toUpperCase(chars[0]);
        return new String(chars);
    }
}

Related

  1. capitalize(String s)
  2. capitalize(String s)
  3. capitalize(String s)
  4. capitalize(String s, char delimiter)
  5. capitalize(String s, String fullstring)
  6. capitalize(String src)
  7. capitalize(String str)
  8. capitalize(String str)
  9. capitalize(String str)