Java String Underscore underScoreCase2CamelCase(String str)

Here you can find the source of underScoreCase2CamelCase(String str)

Description

under Score Case Camel Case

License

Open Source License

Declaration

public static final String underScoreCase2CamelCase(String str) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {

    public static final String underScoreCase2CamelCase(String str) {
        if (!str.contains("_"))
            return str;
        StringBuilder sb = new StringBuilder();
        char[] chars = str.toCharArray();
        boolean hitUnderScore = false;
        sb.append(chars[0]);/*w  w w  . j  a va 2  s.c o  m*/
        for (int i = 1; i < chars.length; i++) {
            char c = chars[i];
            if (c == '_') {
                hitUnderScore = true;
            } else {
                if (hitUnderScore) {
                    sb.append(Character.toUpperCase(c));
                    hitUnderScore = false;
                } else {
                    sb.append(c);
                }
            }
        }
        return sb.toString();
    }

    public static boolean contains(Object arr[], Object... obj) {
        if (arr == null || obj == null || arr.length == 0)
            return false;
        return Arrays.asList(arr).containsAll(Arrays.asList(obj));
    }

    public static String toString(Object object) {
        return toString(object, null);
    }

    public static String toString(Object object, String defaultValue) {
        if (object == null)
            return defaultValue;
        return String.valueOf(object);
    }
}

Related

  1. underscore(String word)
  2. underscoreAllWhitespace(String str)
  3. underscoreAndLowercase(String s)
  4. underScoreBreakToCaseBreak (final String s)
  5. underscoreCase(String s)
  6. underscored(String string)
  7. underscoredToCamel(String string)
  8. underscoreName(String camelCaseName)
  9. underscoreName(String name)