Java String Camel Case cameliza(String str)

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

Description

cameliza

License

Apache License

Declaration

public static String cameliza(String str) 

Method Source Code

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

public class Main {
    public static String cameliza(String str) {
        char[] strCharArray = str.toCharArray();
        int nroEspacos = conta(' ', str);
        char[] strCamelizada = new char[strCharArray.length - nroEspacos];
        for (int i = 0, j = 0; i < strCharArray.length; i++) {
            if (strCharArray[i] != ' ') {
                strCamelizada[j++] = minuscula(strCharArray[i]);
            } else {
                strCamelizada[j++] = maiuscula(strCharArray[++i]);
            }/* w  ww .ja v  a2 s.  c  o  m*/
        }
        return new String(strCamelizada);
    }

    public static int conta(char c, String str) {
        char[] strCharArray = str.toCharArray();
        int ocorrencias = 0;
        for (int i = 0; i < strCharArray.length; i++) {
            if (strCharArray[i] == c) {
                ocorrencias++;
            }
        }
        return ocorrencias;
    }

    public static char minuscula(char c) {
        if (c >= 65 && c <= 90) {
            return (char) (c + 32);
        } else {
            return c;
        }
    }

    public static char maiuscula(char c) {
        if (c >= 97 && c <= 122) {
            return (char) (c - 32);
        } else {
            return c;
        }
    }
}

Related

  1. camelCase(String text)
  2. camelCase(String text)
  3. camelCased(String str)
  4. camelCasedWord(String s)
  5. camelCaseWord(String word)
  6. cameliza(String str)
  7. camelize(String s)
  8. camelize(String underScore)
  9. camelize(String value)