If the string is null or empty, the above code throws an exception. The above example transforms the first letter of string str to uppercase and leaves the rest of the string the same. substring ( 1 ) // print the string System. The simplest way to capitalize the first letter of a string in Java is by using the String.substring() method: String str = "hello world!" // capitalize first letter String output = str. However, there are methods available to change the case of the string (uppercase, lowercase, etc.). Unfortunately, the String class in Java does not provide any method to capitalize string. In this quick tutorial, you will learn how to capitalize the first letter of a string in Java.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |