The [String](<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>) type provides two methods for converting strings between upper case and lower case:

These methods both return the converted strings as new String instances: the original String objects are not modified because String is immutable in Java. See this for more on immutability : Immutability of Strings in Java

String string = "This is a Random String";
String upper = string.toUpperCase();
String lower = string.toLowerCase();

System.out.println(string);   // prints "This is a Random String"
System.out.println(lower);    // prints "this is a random string"
System.out.println(upper);    // prints "THIS IS A RANDOM STRING"

Non-alphabetic characters, such as digits and punctuation marks, are unaffected by these methods. Note that these methods may also incorrectly deal with certain Unicode characters under certain conditions.


Note: These methods are locale-sensitive, and may produce unexpected results if used on strings that are intended to be interpreted independent of the locale. Examples are programming language identifiers, protocol keys, and HTML tags.

For instance, "TITLE".toLowerCase() in a Turkish locale returns “tıtle”, where ı (\\u0131) is the LATIN SMALL LETTER DOTLESS I character. To obtain correct results for locale insensitive strings, pass Locale.ROOT as a parameter to the corresponding case converting method (e.g. toLowerCase(Locale.ROOT) or toUpperCase(Locale.ROOT)).

Although using Locale.ENGLISH is also correct for most cases, the language invariant way is Locale.ROOT.

A detailed list of Unicode characters that require special casing can be found on the Unicode Consortium website.

Changing case of a specific character within an ASCII string:

To change the case of a specific character of an ASCII string following algorithm can be used:

Steps:

  1. Declare a string.
  2. Input the string.
  3. Convert the string into a character array.
  4. Input the character that is to be searched.
  5. Search for the character into the character array.
  6. If found,check if the character is lowercase or uppercase.