Here you can find the source of toJavaConstantIdentifier(String name)
public static String toJavaConstantIdentifier(String name)
//package com.java2s; //License from project: Apache License public class Main { public static String toJavaConstantIdentifier(String name) { StringBuilder s = new StringBuilder(); boolean funnyCharacter = false; for (int i = 0; i < name.length(); i++) { char ch = name.charAt(i); if ((i == 0 && !Character.isJavaIdentifierStart(ch)) || (i > 0 && !Character.isJavaIdentifierPart(ch))) { funnyCharacter = true;// w ww . j av a 2s. co m } else if (funnyCharacter) { s.append("_"); s.append(Character.toUpperCase(ch)); funnyCharacter = false; } else s.append(Character.toUpperCase(ch)); } return s.toString(); } }