Java MCQ: Which of the following is not a method in the ‘String’ class?
a) length()
b) substring()
c) equalsIgnoreCase()
d) size()
Answer:
d) size()
Explanation:
The Java String
class provides a variety of methods for manipulating and inspecting strings. Common methods include length()
for getting the length of the string, substring()
for extracting a portion of the string, and equalsIgnoreCase()
for comparing strings while ignoring case differences.
However, size()
is not a method in the String
class. The correct method for obtaining the length of a string is length()
. Using size()
would result in a compilation error.
Familiarity with the methods available in the String
class is essential for effectively working with string data in Java.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html