Here you can find the source of invertCase(String line)
public static String invertCase(String line)
//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; } }