Here you can find the source of toUpperCase(String s)
public static String toUpperCase(String s)
//package com.java2s; // Licensed under the Academic Free License version 3.0 public class Main { /**// w w w. jav a2s . co m * Do an ASCII only upper case conversion. Case conversion * with Locale can result in unexpected side effects. */ public static char toUpperCase(char c) { if ('a' <= c && c <= 'z') return (char) (c & ~0x20); else return c; } /** * Do an ASCII only upper case conversion. Case conversion * with Locale can result in unexpected side effects. */ public static String toUpperCase(String s) { // first scan to see if string isn't already ok int len = s.length(); int first = -1; for (int i = 0; i < len; ++i) { char a = s.charAt(i); char b = toUpperCase(a); if (a != b) { first = i; break; } } if (first == -1) return s; // allocate new char buf and copy up to first change char[] buf = new char[len]; s.getChars(0, first, buf, 0); // change remainder of string for (int i = first; i < len; ++i) buf[i] = toUpperCase(s.charAt(i)); return new String(buf); } }