Java examples for java.lang:String Case
convert String Camel Case To All Caps
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { String qualifiedClassName = "java2s.com"; System.out.println(convertCamelCaseToAllCaps(qualifiedClassName)); }//from ww w . java 2 s .co m public static String convertCamelCaseToAllCaps(String qualifiedClassName) { StringBuffer sb = new StringBuffer(); final char[] charArray = qualifiedClassName.toCharArray(); for (int c = 0; c < charArray.length; c++) { char character = charArray[c]; final boolean isEnd = c + 1 == charArray.length; boolean nextIsUpper = !isEnd && Character.isUpperCase(charArray[c + 1]); boolean nextNextIsLower = c + 2 < (charArray.length) && Character.isLowerCase(charArray[c + 2]); sb.append(Character.toUpperCase(character)); if (Character.isLowerCase(character) && nextIsUpper) { sb.append('_'); } else { if (nextIsUpper && nextNextIsLower) { sb.append('_'); } } } return sb.toString(); } }