Java String Case Swap swapFirstLetterCase(String str)

Here you can find the source of swapFirstLetterCase(String str)

Description

convert first letter to a big letter or a small letter.
 StringUtil.trim('Password') = 'password' StringUtil.trim('password') = 'Password' 

License

Apache License

Parameter

Parameter Description
str String to be swapped

Return

String converting result

Declaration

public static String swapFirstLetterCase(String str) 

Method Source Code

//package com.java2s;
/*//from   ww w  .  j  av a  2 s . c  om
 * Copyright 2008-2009 MOPAS(Ministry of Public Administration and Security).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * convert first letter to a big letter or a small
     * letter.<br>
     * 
     * <pre>
     * StringUtil.trim('Password') = 'password'
     * StringUtil.trim('password') = 'Password'
     * </pre>
     * @param str
     *        String to be swapped
     * @return String converting result
     */
    public static String swapFirstLetterCase(String str) {
        StringBuffer sbuf = new StringBuffer(str);
        sbuf.deleteCharAt(0);
        if (Character.isLowerCase(str.substring(0, 1).toCharArray()[0])) {
            sbuf.insert(0, str.substring(0, 1).toUpperCase());
        } else {
            sbuf.insert(0, str.substring(0, 1).toLowerCase());
        }
        return sbuf.toString();
    }
}

Related

  1. swapCase(String str)
  2. swapCase(String str)
  3. swapCase(String str)
  4. swapCase(String str)
  5. swapCase(String str)