Java String Upper Case toUpperCase(String string)

Here you can find the source of toUpperCase(String string)

Description

A locale independent version of toUpperCase.

License

Apache License

Parameter

Parameter Description
string input to be converted

Return

a US Ascii uppercase version

Declaration

public static String toUpperCase(String string) 

Method Source Code

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

public class Main {
    /**/* w w  w  . j  a  v  a  2s. co m*/
     * A locale independent version of toUpperCase.
     *
     * @param string input to be converted
     * @return a US Ascii uppercase version
     */
    public static String toUpperCase(String string) {
        boolean changed = false;
        char[] chars = string.toCharArray();

        for (int i = 0; i != chars.length; i++) {
            char ch = chars[i];
            if ('a' <= ch && 'z' >= ch) {
                changed = true;
                chars[i] = (char) (ch - 'a' + 'A');
            }
        }

        if (changed) {
            return new String(chars);
        }

        return string;
    }
}

Related

  1. toUpperCase(String src)
  2. toUpperCase(String str)
  3. toUpperCase(String str)
  4. toUpperCase(String str)
  5. toUpperCase(String str)
  6. toUpperCase(String string)
  7. toUpperCase(String text)
  8. toUpperCase(String text)
  9. toUpperCase(String text)