Question:

Which of the following method of string class returns a string with all characters of invoking string converted to uppercase in Java?

Show Hint

The {toUpperCase()} method converts all letters in a string to uppercase while leaving the original string unchanged.
  • String toChangeCase()
  • String toCapCase()
  • String toUpperCase()
  • String toUpCase()
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: Understanding string manipulation methods.
The Java String class provides several built-in methods that allow programmers to manipulate string values. These methods can change the format of strings, search for characters, compare strings, and convert letter cases.
Step 2: Understanding the toUpperCase() method.
The toUpperCase() method converts all characters in a string to uppercase letters. This method does not change the original string because strings in Java are immutable. Instead, it returns a new string containing the converted characters.
Example:
String text = "hello";
System.out.println(text.toUpperCase());
Output:
HELLO
Step 3: Evaluation of options.
(A) String toChangeCase(): Incorrect. This method does not exist in Java.
(B) String toCapCase(): Incorrect. This is not a valid Java method.
(C) String toUpperCase(): Correct. This method converts all characters of a string to uppercase.
(D) String toUpCase(): Incorrect. This method is not defined in Java.
Step 4: Conclusion.
Therefore, the method used to convert all characters of a string to uppercase is toUpperCase().
Final Answer: toUpperCase()
Was this answer helpful?
0
0