Java String Case Insert invertCase(String line)

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

Description

invert Case

License

Open Source License

Declaration

public static String invertCase(String line) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004 Andrei Loskutov./*w w  w.  j av a  2  s  .c  om*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the BSD License
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/bsd-license.php
 * Contributor:  Andrei Loskutov - initial API and implementation
 *******************************************************************************/

public class Main {
    public static String invertCase(String line) {
        char[] chars = line.toCharArray();
        char c;
        boolean changed = false;
        for (int i = 0; i < chars.length; i++) {
            c = chars[i];
            // XXX DOESN'T WORK WITH UNICODE SPECIAL CHARS!!!!
            if (Character.isLowerCase(c)) {
                chars[i] = Character.toUpperCase(c);
                changed = true;
            } else if (Character.isUpperCase(c)) {
                chars[i] = Character.toLowerCase(c);
                changed = true;
            }
        }
        if (changed) {
            return String.valueOf(chars);
        }
        return line;
    }
}

Related

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