In this article we’ll tell about several ways to make the first character of String from Uppercase to Lowercase.

Use charAt() and substring() methods:

String string = "Codeyz";
String result = Character.toLowerCase(string.charAt(0)) + string.substring(1);
// result: codeyz

At the beginning, the String is converted to char array, then convert first char to lowercase:

String string = "Codeyz"; 
char[] c = string.toCharArray();
c[0] = Character.toLowerCase(c[0]);
String result = new String(c);
// result: codeyz

As a previous example, at the beginning, the String is converted to char array, then plus 32 character:

String string = "Codeyz"; 
char[] c = string.toCharArray();
c[0] += 32;
String result = new String(c);
// result: codeyz

In this example we use StringBuilder class:

String string = "Codeyz";
StringBuilder sb = new StringBuilder(string);
sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
String result = sb.toString();
// result: codeyz

Using two methods substring():

String string = "Codeyz";
String result = string.substring(0, 1).toLowerCase() + string.substring(1);
// result: codeyz

And the most  unusual method, with using Introspector class from java.beans.Introspector:

String string = "Codeyz";
String result = Introspector.decapitalize(string);
// result: codeyz

One thought on “Several ways to make the first character of a String to lowercase”

Leave a Reply

Your email address will not be published.