Short answerModerate2 marks
What is the data type returned by the following library methods? (i) isWhitespace() (ii) compareToIgnoreCase()
Topic: Return types of library methods
Previous-year question practice database
Answer
Exam answer
(i) boolean (ii) int
Explanation
Classify by what each method answers. (i) Character.isWhitespace(ch) answers a yes-or-no question — is this character a space, tab or newline? — so it returns boolean. (ii) compareToIgnoreCase() compares two strings and returns the difference of the ASCII codes at the first differing position, ignoring case. That is a number, so the type is int, and it may be negative. Group them in your mind: the is... methods return boolean, the compare... methods return int, the to... methods return char or String.
More from Library Classes
What is the output of the statement Math.pow(36, 6/5);?2026The output of the statement:
System.out.println(Character.toUpperCase('b') + 2); is:2026What is the type of parameter to be given for the method parseInt()?2026Write the Java expression to find the sum of cube root of x and the absolute value of y.2026Character class methods are found in the package called:2025The output of Math.max(-7, Math.min(-5, -4)) is2025