In Java, you can convert a String to different cases, such as lowercase or uppercase, using the following methods:
Converting to lowercase:
Using the toLowerCase() method: String lowercaseString = originalString.toLowerCase();
Converting to uppercase:
Using the toUpperCase() method: String uppercaseString = originalString.toUpperCase();
Here's an example that demonstrates how to convert a String to different cases:
public class StringCaseConversionExample {
public static void main(String[] args) {
String originalString = "Hello, World!";
String lowercaseString = originalString.toLowerCase();
System.out.println("Lowercase: " + lowercaseString);
String uppercaseString = originalString.toUpperCase();
System.out.println("Uppercase: " + uppercaseString);
}
}
No comments:
Post a Comment