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

public static String capitalizeFirstChar(String name) {
    if (name == null || name.length() == 0) {
        return name;
    }//from www. j  a v  a  2  s  .  com
    if (name.startsWith("_")) {
        return capitalizeFirstChar(name.substring(1));
    }
    char chars[] = name.toCharArray();
    chars[0] = Character.toUpperCase(chars[0]);
    return new String(chars);
}

From source file:Main.java

public static String abbreviate(String text) {
    String[] words = text.split("\\s");

    StringBuilder builder = new StringBuilder();
    int i = 0;//from  w  w  w . java  2  s .  c o  m
    while (i < words.length && builder.length() < 2) {
        String word = words[i].trim();
        if (word.length() > 0)
            builder.append(Character.toUpperCase(word.charAt(0)));
        i++;
    }

    return builder.toString();
}

From source file:Main.java

public static String capitalizeWords(String s) {
    StringBuilder sb = new StringBuilder();
    String[] words = s.split("\\s+");

    for (int i = 0; i < words.length; i++) {
        String word = words[i];/*from   w  ww . j a  va  2s .c  om*/
        if (word.length() > 0) {
            sb.append(Character.toUpperCase(word.charAt(0)));
            if (word.length() > 1) {
                sb.append(word.substring(1));
            }
        }

        if (i < words.length - 1) {
            sb.append(" ");
        }
    }

    return sb.toString();
}

From source file:Main.java

/** 
 * Returns the KeyEvent-code (only for VK_a..Z).
 * If no key-event could be found, {@link Integer#MIN_VALUE} is returned. 
 */// w  w w.j a v a  2  s  .  c  om
public static int getKeyEvent(Character ch) {

    int ke = Integer.MIN_VALUE;
    try {
        Field f = KeyEvent.class.getField("VK_" + Character.toUpperCase(ch));
        f.setAccessible(true);
        ke = (Integer) f.get(null);
    } catch (Exception e) {
    }
    return ke;
}

From source file:Main.java

public static List<String> collectAsString(List<? extends Object> objects, String fieldName) {

    List<String> stringsAsAttribute = new ArrayList<String>();

    String getterName = "get" + Character.toUpperCase(fieldName.charAt(0))
            + fieldName.substring(1, fieldName.length());
    try {/* w  w w  . j a va2 s  . c  o m*/

        for (Object object : objects) {
            Method getterMethod = object.getClass().getMethod(getterName);
            Object result = getterMethod.invoke(object);
            stringsAsAttribute.add(result.toString());
        }

    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return stringsAsAttribute;
}

From source file:Main.java

public static String upperFirst(String str) {
    return Character.toUpperCase(str.charAt(0)) + str.substring(1);
}

From source file:Main.java

public static String toConstantFormat(String str) {
    int n = str.length();
    List<Character> list = new ArrayList<Character>();
    char c;/*  w ww .j  a v a  2  s.com*/
    for (int i = 0; i < n; i++) {
        c = str.charAt(i);
        if (i != 0 && Character.isUpperCase(c)) {
            list.add('_');
        }
        list.add(Character.toUpperCase(c));
    }

    StringBuffer buffer = new StringBuffer();
    for (Character character : list) {
        buffer.append(character);
    }
    return buffer.toString();
}

From source file:Main.java

/**
 * @param str str//from w w w  .  ja v a  2  s  .c  o  m
 * @return String
 */
public static String capitalizeFirstLetter(String str) {

    if (isEmpty(str)) {
        return str;
    }

    char c = str.charAt(0);
    return (!Character.isLetter(c) || Character.isUpperCase(c)) ? str
            : new StringBuilder(str.length()).append(Character.toUpperCase(c)).append(str.substring(1))
                    .toString();
}

From source file:Main.java

public static String getIntiCapString(String param) {
    if (param != null && param.length() > 0) {
        char[] charArray = param.toCharArray();
        charArray[0] = Character.toUpperCase(charArray[0]);
        return new String(charArray);
    } else {/*from w w  w  .  j  a v a 2s . c om*/
        return "";
    }
}

From source file:Main.java

static private String capitalize(String s) {
    if (s == null || s.length() == 0) {
        return "";
    }/*  w  w  w .j  a v a2  s .co  m*/
    char first = s.charAt(0);
    if (Character.isUpperCase(first)) {
        return s;
    } else {
        return Character.toUpperCase(first) + s.substring(1);
    }
}