Java String Camel Case Format toCamelCase(String s)

Here you can find the source of toCamelCase(String s)

Description

to Camel Case

License

Open Source License

Declaration

public static String toCamelCase(String s) 

Method Source Code

//package com.java2s;

public class Main {
    public static String toCamelCase(String s) {
        if (s == null)
            return null;
        if (s.isEmpty() || !Character.isLetter(s.codePointAt(0)))
            return s;
        char prefix = s.charAt(0);
        prefix = Character.toUpperCase(prefix);

        String suffix = s.substring(1);
        // check to see if suffix has lower case letters, in which case it is
        // assumed to already be camel case.
        for (int i = 0; i < suffix.length(); ++i) {
            char c = suffix.charAt(i);
            if (Character.isLowerCase(c)) {
                suffix = suffix.toLowerCase();
                break;
            }/*ww w.  j av a  2  s.  c om*/
        }

        return prefix + suffix;
    }
}

Related

  1. toCamelCase(String s)
  2. toCamelCase(String s)
  3. toCamelCase(String s)
  4. toCamelCase(String s)
  5. toCamelCase(String s)
  6. toCamelCase(String s)
  7. toCamelCase(String s)
  8. toCamelCase(String s)
  9. toCamelCase(String s, boolean firstCharUppercase)