Java String Camel Case Format toCamelCase(String name)

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

Description

to Camel Case

License

Apache License

Declaration

public static StringBuilder toCamelCase(String name) 

Method Source Code

//package com.java2s;
//Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    public static StringBuilder toCamelCase(String name) {
        StringBuilder buffer = new StringBuilder();
        int toUpper = 0;
        char c;/*from   w ww .  ja v  a2 s.  c o m*/
        for (int i = 0, len = name.length(); i < len;) {
            c = name.charAt(i++);
            if (c == '_') {
                if (i == len)
                    break;
                if (buffer.length() != 0)
                    toUpper++;
                continue;
            } else if (toUpper != 0) {
                if (c > 96 && c < 123) {
                    buffer.append((char) (c - 32));
                    toUpper = 0;
                } else if (c > 64 && c < 91) {
                    buffer.append(c);
                    toUpper = 0;
                } else {
                    while (toUpper > 0) {
                        buffer.append('_');
                        toUpper--;
                    }
                    buffer.append(c);
                }
            } else {
                if (buffer.length() == 0 && c > 64 && c < 91)
                    buffer.append((char) (c + 32));
                else
                    buffer.append(c);
            }
        }
        return buffer;
    }
}

Related

  1. toCamelCase(String name)
  2. toCamelCase(String name)
  3. toCamelCase(String name)
  4. toCamelCase(String name)
  5. toCamelCase(String name)
  6. toCamelCase(String name)
  7. toCamelCase(String original)
  8. toCamelCase(String originalName)
  9. toCamelCase(String origString)