Java String Upper Case toUpperCase(String str)

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

Description

to Upper Case

License

Open Source License

Declaration

public static String toUpperCase(String str) 

Method Source Code

//package com.java2s;
/*/*w  w  w.  j a va  2  s.  c  o  m*/
 * JBoss, Home of Professional Open Source.
 *
 * See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
 *
 * See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
 */

public class Main {
    public static String toUpperCase(String str) {
        String newStr = convertBasicLatinToUpper(str);
        if (newStr == null) {
            return str.toUpperCase();
        }
        return newStr;
    }

    private static String convertBasicLatinToUpper(String str) {
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (isBasicLatinLowerCase(chars[i])) {
                chars[i] = (char) ('A' + (chars[i] - 'a'));
            } else if (!isBasicLatinChar(chars[i])) {
                return null;
            }
        }
        return new String(chars);
    }

    private static boolean isBasicLatinLowerCase(char c) {
        return c >= 'a' && c <= 'z';
    }

    private static boolean isBasicLatinChar(char c) {
        return c <= '\u007F';
    }
}

Related

  1. toUpperCase(String s, int start, int end)
  2. toUpperCase(String source)
  3. toUpperCase(String src)
  4. toUpperCase(String str)
  5. toUpperCase(String str)
  6. toUpperCase(String str)
  7. toUpperCase(String string)
  8. toUpperCase(String string)
  9. toUpperCase(String text)