Java String Case Swap swapCase(String str)

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

Description

swap Case

License

Apache License

Declaration

public static String swapCase(String str) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String swapCase(String str) {
        int strLen;
        if ((str == null) || ((strLen = str.length()) == 0)) {
            return str;
        }/*from   w  w w  .ja  va2 s.  com*/
        StringBuffer buffer = new StringBuffer(strLen);

        char ch = '\000';
        for (int i = 0; i < strLen; i++) {
            ch = str.charAt(i);
            if (Character.isUpperCase(ch)) {
                ch = Character.toLowerCase(ch);
            } else if (Character.isTitleCase(ch)) {
                ch = Character.toLowerCase(ch);
            } else if (Character.isLowerCase(ch)) {
                ch = Character.toUpperCase(ch);
            }
            buffer.append(ch);
        }
        return buffer.toString();
    }
}

Related

  1. swapCase(final String str)
  2. swapCase(String str)
  3. swapCase(String str)
  4. swapCase(String str)
  5. swapCase(String str)
  6. swapCase(String str)
  7. swapFirstLetterCase(String str)