Java Java String Format toJavaIdentifier(String name)

Here you can find the source of toJavaIdentifier(String name)

Description

to Java Identifier

License

Apache License

Declaration

public static String toJavaIdentifier(String name) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String toJavaIdentifier(String name) {

        StringBuilder s = new StringBuilder();
        boolean capitalize = false;
        for (int i = 0; i < name.length(); i++) {
            char ch = name.charAt(i);
            if ((i != 0 && !Character.isJavaIdentifierStart(ch)) || !Character.isJavaIdentifierPart(ch)) {
                capitalize = true;//  w w w.j a  va 2 s. c  om
            } else if (capitalize) {
                s.append(Character.toUpperCase(ch));
                capitalize = false;
            } else
                s.append(ch);
        }
        return lowerFirst(s.toString());
    }

    public static String lowerFirst(String s) {
        return s.substring(0, 1).toLowerCase() + s.substring(1);
    }
}

Related

  1. toJavaConstantIdentifier(String name)
  2. toJavadocComment(String comment)
  3. toJavaEnum(String inStr)
  4. toJavaHex(byte in[], int len)
  5. toJavaHexCharString(final char chr)
  6. toJavaIdentifier(String name)
  7. toJavaIdentifier(String nodeName, boolean boundary)
  8. toJavaIdentifier(String s)
  9. toJavaIdentifier(String source)