Example usage for java.lang Character toUpperCase

List of usage examples for java.lang Character toUpperCase

Introduction

In this page you can find the example usage for java.lang Character toUpperCase.

Prototype

public static int toUpperCase(int codePoint) 

Source Link

Document

Converts the character (Unicode code point) argument to uppercase using case mapping information from the UnicodeData file.

Usage

From source file:Main.java

static String capitalize(final String word) {
    return Character.toUpperCase(word.charAt(0)) + word.substring(1);
}

From source file:Main.java

private static String changeFirstCharacterCase(String str, boolean capitalize) {
    if (str == null || str.length() == 0) {
        return str;
    }//from  w  ww .  j a v  a 2s  .c o  m
    StringBuilder sb = new StringBuilder(str.length());
    if (capitalize) {
        sb.append(Character.toUpperCase(str.charAt(0)));
    } else {
        sb.append(Character.toLowerCase(str.charAt(0)));
    }
    sb.append(str.substring(1));
    return sb.toString();
}

From source file:Main.java

/**
 * /* ww  w .  j  a va  2 s.  com*/
 * @param obj
 * @param property
 * @return
 */
public static Object getValue(Object obj, String property) {
    if (property.equalsIgnoreCase("")) {
        return obj;
    }
    String methodName = "get" + Character.toUpperCase(property.charAt(0)) + property.substring(1);
    try {
        if (obj == null)
            return obj;
        Method getterMethod = obj.getClass().getMethod(methodName);
        obj = getterMethod.invoke(obj);
    } catch (Exception e) {
        System.out.println("Error getting property value using getter method " + methodName + " of class "
                + obj.getClass().getName());
    }
    return obj;
}

From source file:Main.java

public static String capitalize(String s) {
    if (TextUtils.isEmpty(s)) {
        return "";
    }//  w  w w .  ja  va  2  s  .c  om
    final char first = s.charAt(0);
    if (Character.isUpperCase(first)) {
        return s;
    } else {
        return Character.toUpperCase(first) + s.substring(1);
    }
}

From source file:Main.java

public static boolean containsIgnoreCase(String src, String what) {
    final int length = what.length();
    if (length == 0)
        return true; // Empty string is contained

    final char firstLo = Character.toLowerCase(what.charAt(0));
    final char firstUp = Character.toUpperCase(what.charAt(0));

    for (int i = src.length() - length; i >= 0; i--) {
        // Quick check before calling the more expensive regionMatches() method:
        final char ch = src.charAt(i);
        if (ch != firstLo && ch != firstUp)
            continue;

        if (src.regionMatches(true, i, what, 0, length))
            return true;
    }/*  w  w  w .ja  va  2  s. c o  m*/

    return false;
}

From source file:Main.java

public static String convertCamelCaseToAllCaps(String qualifiedClassName) {
    StringBuffer sb = new StringBuffer();
    final char[] charArray = qualifiedClassName.toCharArray();
    for (int c = 0; c < charArray.length; c++) {
        char character = charArray[c];
        final boolean isEnd = c + 1 == charArray.length;
        boolean nextIsUpper = !isEnd && Character.isUpperCase(charArray[c + 1]);
        boolean nextNextIsLower = c + 2 < (charArray.length) && Character.isLowerCase(charArray[c + 2]);

        sb.append(Character.toUpperCase(character));
        if (Character.isLowerCase(character) && nextIsUpper) {
            sb.append('_');
        } else {//from   w  w w. j  av  a 2 s .  co m
            if (nextIsUpper && nextNextIsLower) {
                sb.append('_');
            }
        }
    }
    return sb.toString();
}

From source file:Main.java

private static final String capitalize(String str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }/* ww w  . j  av a 2 s  .  c om*/
    final char[] arr = str.toCharArray();
    boolean capitalizeNext = true;
    String phrase = "";
    for (final char c : arr) {
        if (capitalizeNext && Character.isLetter(c)) {
            phrase += Character.toUpperCase(c);
            capitalizeNext = false;
            continue;
        } else if (Character.isWhitespace(c)) {
            capitalizeNext = true;
        }
        phrase += c;
    }
    return phrase;
}

From source file:Main.java

public static String firstLetterToUpperCase(String name) {
    if (name.trim().length() == 0) {
        return name;
    }/*from   w w w.j av a  2  s  .  c  om*/
    char c[] = name.toCharArray();
    c[0] = Character.toUpperCase(c[0]);
    name = new String(c);
    return name;
}

From source file:Main.java

static synchronized String toCamelCase(String str) {
    if (str == null)
        return null;
    int pos = 0;/*  w ww .  ja  va 2s. c  om*/
    boolean doCapitalize = true;
    for (int i = 0; i < str.length(); ++i) {
        char ch = str.charAt(i);
        if (Character.isLetterOrDigit(ch)) {
            if (doCapitalize && Character.isLetter(ch)) {
                ch = Character.toUpperCase(ch);
            }
            sCamelCase[pos] = ch;
            ++pos;
            doCapitalize = false;
        } else if (ch == '_') {
            doCapitalize = true;
        }
    }

    return new String(sCamelCase, 0, pos);
}

From source file:Main.java

public static String tagNameToFieldName(String tagName) {
    int minusIndex = tagName.indexOf('-');
    while (minusIndex != -1) {
        char nextChar = tagName.charAt(minusIndex + 1);
        char upper = Character.toUpperCase(nextChar);
        StringBuilder sb = new StringBuilder(tagName);
        sb.replace(minusIndex + 1, minusIndex + 2, new String(new char[] { upper }));
        sb.replace(minusIndex, minusIndex + 1, "");
        tagName = sb.toString();//from   ww  w.j  ava2 s .  co  m
        minusIndex = tagName.indexOf('-');
    }
    return tagName;
}