Here you can find the source of capitalize(String source)
Parameter | Description |
---|---|
source | The <code>String</code> to capitalize. |
String
.
public static String capitalize(String source)
//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); } }