Caplitalize a string
In this chapter you will learn:
Caplitalize a string
public class Main {
public static void main(String[] argv){
System.out.println(caps("this is a test from java2s.com."));
}/*ja v a 2 s.co m*/
public static String caps(String string) {
if (string.length() == 0) {
return string;
}
char ch = string.charAt(0);
if (Character.isLowerCase(ch)) {
ch = Character.toUpperCase(ch);
return ch + string.substring(1);
}
return string;
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » String