If string is not
in proper case i.e. if a particular name's all letters are in upper
case or lower case, so this code will convert it to proper case.
public class ConvertToProperCase { public static String convertToProper(String strToConvert) throws java.io.IOException{ //get lower case string java.io.StringReader str = new java.io.StringReader(strToConvert.toLowerCase()); boolean precededBySpace = true; StringBuffer properCase = new StringBuffer(); while(true) { //read string character by character int i = str.read(); if (i == -1) break; char c = (char)i; if (c == ' ' || c == '"' || c == '(' || c == '.' || c == '/' || c == '\' || c == ',') { properCase.append(c); precededBySpace = true; } else { if (precededBySpace) { //convert first character to proper properCase.append(Character.toUpperCase(c)); } else { // append rest character properCase.append(c); } precededBySpace = false; } } return properCase.toString(); } //main code public static void main(String[] args) { try { //call convertToProper method System.out.println(convertToProper("1jf94osl TEST TEST test test., MIKE, BRADD, blair")); } catch (java.io.IOException e) { System.out.println("Exception:" + e); } } }