Example usage for java.lang Character toTitleCase

List of usage examples for java.lang Character toTitleCase

Introduction

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

Prototype

public static int toTitleCase(int codePoint) 

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] argv) {
    System.out.println(Character.toTitleCase('t'));

}

From source file:Main.java

public static void main(String[] args) {
    int cp1 = 0x0068;
    int cp2 = 0x005c;

    int cp3 = Character.toTitleCase(cp1);
    int cp4 = Character.toTitleCase(cp2);

    String str1 = "Titlecase equivalent of " + cp1 + " is " + cp3;
    String str2 = "Titlecase equivalent of " + cp2 + " is " + cp4;

    System.out.println(str1);/*from   w ww .j a v a2 s  .c o  m*/
    System.out.println(str2);
}

From source file:TasteOfThingsV1.java

 public static void main(String args[]) throws Exception {
   prepareData();// www  .j  a  va  2s.  c o m

   HashBag myBag = new HashBag(testMap.values());

   System.err.println("How many Boxes? " + myBag.getCount("Boxes"));
   myBag.add("Boxes", 5);
   System.err.println("How many Boxes now? " + myBag.getCount("Boxes"));

   Method method =
     testBean.getClass().getDeclaredMethod("getTestMap", new Class[0]);
   HashMap reflectionMap =
     (HashMap)method.invoke(testBean, new Object[0]);
   System.err.println("The value of the 'squ' key using reflection: " +
     reflectionMap.get("squ"));

   String squ = BeanUtils.getMappedProperty(testBean, "testMap", "squ");
   squ = StringUtils.capitalize(squ);

   PropertyUtils.setMappedProperty(testBean, "testMap", "squ", squ);

   System.err.println("The value of the 'squ' key is: " +
     BeanUtils.getMappedProperty(testBean, "testMap", "squ"));

   String box = (String)testMap.get("box");
   String caps =
     Character.toTitleCase(box.charAt(0)) +
     box.substring(1, box.length());
   System.err.println("Capitalizing boxes by Java: " + caps);
}

From source file:Main.java

public static String capitalize(final String str) {
    if (str.length() == 0) {
        return "";
    }//from w  ww .  j a  va 2  s . c o m

    final char[] buffer = str.toCharArray();
    buffer[0] = Character.toTitleCase(buffer[0]);

    for (int i = 1; i < buffer.length; i++) {
        if (buffer[i - 1] == ' ') {
            buffer[i] = Character.toTitleCase(buffer[i]);
        }
    }
    return new String(buffer);
}

From source file:Main.java

public static String capitalizeWord(String str) {
    int strLen;// ww  w . ja v  a 2  s  .c o  m
    if (str == null || (strLen = str.length()) == 0) {
        return str;
    }
    return new StringBuilder(strLen).append(Character.toTitleCase(str.charAt(0))).append(str.substring(1))
            .toString();
}

From source file:Main.java

/**
 * Converts a string to title casing.//from  w w  w.  ja  va2 s. com
 * @param str
 *      The string to convert.
 * @return
 *      The converted string.
 */
public static String toTitleCase(String str) {
    if (str == null) {
        return null;
    }
    // skip if already contains mixed case
    if (!str.equals(str.toLowerCase()) && !str.equals(str.toUpperCase())) {
        return str;
    }

    boolean isSeparator = true;
    StringBuilder builder = new StringBuilder(str);
    final int len = builder.length();

    for (int i = 0; i < len; ++i) {
        char c = builder.charAt(i);
        if (isSeparator) {
            if (Character.isLetterOrDigit(c)) {
                // Convert to title case and switch out of whitespace mode.
                builder.setCharAt(i, Character.toTitleCase(c));
                isSeparator = false;
            }
        } else if (!Character.isLetterOrDigit(c)) {
            isSeparator = true;
        } else {
            builder.setCharAt(i, Character.toLowerCase(c));
        }
    }

    return builder.toString();
}

From source file:Main.java

/**
 * Converts a string to title casing.//from   www .j a va 2s  .  c o m
 *
 * @param str The string to convert.
 * @return The converted string.
 */
public static String toTitleCase(String str) {
    if (str == null) {
        return null;
    }

    boolean isSeparator = true;
    StringBuilder builder = new StringBuilder(str);
    final int len = builder.length();

    for (int i = 0; i < len; ++i) {
        char c = builder.charAt(i);
        if (isSeparator) {
            if (Character.isLetterOrDigit(c)) {
                // Convert to title case and switch out of whitespace mode.
                builder.setCharAt(i, Character.toTitleCase(c));
                isSeparator = false;
            }
        } else if (!Character.isLetterOrDigit(c)) {
            isSeparator = true;
        } else {
            builder.setCharAt(i, Character.toLowerCase(c));
        }
    }

    return builder.toString();
}

From source file:Main.java

/**
 * <p>//  ww  w.  j a  v  a  2 s.co  m
 * Capitalise a String.
 * </p>
 * <p/>
 * <p>
 * That is, convert the first character into title-case. <code>null</code> is returned as <code>null</code>.
 * </p>
 *
 * @param str the String to capitalise
 * @return capitalised String
 */
public static String capitalise(String str) {
    if (str == null) {
        return null;
    } else if (str.length() == 0) {
        return "";
    } else {
        return new StringBuilder(str.length()).append(Character.toTitleCase(str.charAt(0)))
                .append(str.substring(1)).toString();
    }
}

From source file:Main.java

/**
 * Convert the first character of the given String to uppercase. This method will <i>not</i> trim of spaces!
 * <p>//from   w  ww  . j  ava  2s .c o  m
 * <b>Attention:</b> this method will currently throw a <code>IndexOutOfBoundsException</code> for empty strings!
 * </p>
 *
 * @param data the String to get capitalized
 * @return data string with the first character transformed to uppercase
 * @throws NullPointerException if data is <code>null</code>
 */
public static String capitalizeFirstLetter(String data) {
    char firstLetter = Character.toTitleCase(data.substring(0, 1).charAt(0));

    String restLetters = data.substring(1);

    return firstLetter + restLetters;
}

From source file:Main.java

/**
 * <p>//from w  w w .j av a 2 s. c  o m
 * Capitalise all the words in a String.
 * </p>
 * <p/>
 * <p>
 * Uses {@link Character#isWhitespace(char)} as a separator between words.
 * </p>
 * <p/>
 * <p>
 * <code>null</code> will return <code>null</code>.
 * </p>
 *
 * @param str the String to capitalise
 * @return capitalised String
 */
public static String capitaliseAllWords(String str) {
    if (str == null) {
        return null;
    }
    int sz = str.length();
    StringBuilder buffer = new StringBuilder(sz);
    boolean space = true;
    for (int i = 0; i < sz; i++) {
        char ch = str.charAt(i);
        if (Character.isWhitespace(ch)) {
            buffer.append(ch);
            space = true;
        } else if (space) {
            buffer.append(Character.toTitleCase(ch));
            space = false;
        } else {
            buffer.append(ch);
        }
    }
    return buffer.toString();
}