convert a string to uppercase in java
Code snippet on how to convert a string to uppercase in java
String myString = "hello world";
String upperString = myString.toUpperCase();
System.out.println(upperString);
This code sample converts the string “hello world” into all uppercase, and prints it to the console.
The first line declares a variable called ‘myString’ and assigns it the value “hello world”.
The second line calls the method ‘.toUpperCase()’ on the ‘myString’ variable, and assigns the result to a new variable called ‘upperString’. This method takes the value of ‘myString’ and converts all of the letters to uppercase.
The third and final line prints the ‘upperString’ variable to the console. By doing this, the converted uppercase version of “hello world” is printed.