Logo Search packages:      
Sourcecode: libcommons-lang-java version File versions  Download package

static String org::apache::commons::lang::StringUtils::swapCase ( String  str  )  [inline, static]

Swaps the case of a String changing upper and title case to lower case, and lower case to upper case.

  • Upper case character converts to Lower case
  • Title case character converts to Lower case
  • Lower case character converts to Upper case

For a word based alorithm, see WordUtils#swapCase(String). A null input String returns null.

 StringUtils.swapCase(null)                 = null
 StringUtils.swapCase("")                   = ""
 StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"

NOTE: This method changed in Lang version 2.0. It no longer performs a word based alorithm. If you only use ASCII, you will notice no change. That functionality is available in WordUtils.

str the String to swap case, may be null
the changed String, null if null String input

Definition at line 3568 of file StringUtils.java.

        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return str;
        StringBuffer buffer = new StringBuffer(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);
        return buffer.toString();

Generated by  Doxygen 1.6.0   Back to index