Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

How can I make only the first character of a String uppercase and the remaining lowercase?

How can I make only the first letter of a String uppercase and keep the remaining characters lowercase? For example: "BlAh", "bLah", "bLAH" will become "Blah"

Is there anything in the Java libraries for this?
0
Eindoofus
Asked:
Eindoofus
  • 3
1 Solution
 
CEHJCommented:
You could do
static public String capitalize(String s) {
		return Character.toUpperCase(s.charAt(0)) + s.substring(1);
	}

Open in new window

0
 
EindoofusAuthor Commented:
Thanks, and what command do I use for the remaining characters in s.substring to make them lower case?
0
 
CEHJCommented:
You can do
return Character.toUpperCase(s.charAt(0)) + s.substring(1).toLowerCase();

Open in new window

0
 
CEHJCommented:
:)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now