Here you can find the source of swapCase(String str)
public static String swapCase(String str)
//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 ww w. j a v a2s . c om StringBuilder buffer = 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); } buffer.append(ch); } return buffer.toString(); } public static String toLowerCase(String str) { if (str == null) { return null; } return str.toLowerCase(); } public static String toUpperCase(String str) { if (str == null) { return null; } return str.toUpperCase(); } /** * if <code>obj</code> is null, returns empty string. otherwise returns * <code>obj.toString()</code> * * @param obj * any ref you want * @return <code>obj</code> or <code>obj.toString()</code> */ public static String toString(Object obj) { return obj == null ? "" : obj.toString(); } }