Java tutorial
//package com.java2s; public class Main { public static String replaceUpCase(String str) { StringBuffer sb = new StringBuffer(); char[] c = str.toCharArray(); for (int i = 0; c != null && i < c.length; i++) { if (i == 0) { sb.append(("" + c[i]).toUpperCase()); } else if (c[i] < 97) { sb.append(("_" + c[i])); } else { sb.append(c[i]); } } return sb.toString(); } }