Make the first letter caps and the rest lowercase in Java
Description
The following code shows how to make the first letter caps and the rest lowercase.
Example
// ww w . jav a 2s.c o m
public class Main {
public static void main(String[] argv) {
System.out.println(firstLetterCaps("this is a test from java2s.com"));
}
static public String firstLetterCaps(String data) {
String firstLetter = data.substring(0, 1).toUpperCase();
String restLetters = data.substring(1).toLowerCase();
return firstLetter + restLetters;
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »