Looking to get a head start on your next software interview? Pickup a copy of the best book to prepare: Cracking The Coding Interview!
Here is an example code snippet that demonstrates how to use the `toUpperCase()` method:
String str = "hello world";
String upperCaseStr = str.toUpperCase();
In this example, we first create a string `str` with the value “hello world”. We then call the `toUpperCase()` method on this string and assign the result to a new string `upperCaseStr`. Finally, we print the value of `upperCaseStr` to the console, which will output “HELLO WORLD”.
It is important to note that the `toUpperCase()` method does not modify the original string. Instead, it returns a new string with the uppercase characters. If you want to modify the original string, you can assign the result of the `toUpperCase()` method back to the original string variable.