Java String Case Insert invertCase(String str)

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

Description

invert Case

License

Open Source License

Declaration

public static String invertCase(String str) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String invertCase(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return str;
        }//w w  w.  jav a 2  s  .  c om
        StringBuilder builder = new StringBuilder(strLen);

        char ch = 0;
        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);
            }
            builder.append(ch);
        }
        return builder.toString();
    }
}

Related

  1. invert(final String s)
  2. invert(String s)
  3. invertCase(String line)
  4. invertDate(String sDate)
  5. inverter(String str)
  6. inverter(String string)
  7. inverterString(String palavra)