Explore topic-wise MCQs in Java.

This section includes 11 Mcqs, each offering curated multiple-choice questions to sharpen your Java knowledge and support exam preparation. Choose a topic below to get started.

1.

What does public int start() return?

A. returns start index of the input string
B. returns start index of the current match
C. returns start index of the previous match
D. none of the mentioned
Answer» D. none of the mentioned
2.

what does public String replaceAll(string replace) do?

A. Replace all characters that matches pattern with a replacement string
B. Replace first subsequence that matches pattern with a replacement string
C. Replace all other than first subsequence of that matches pattern with a replacement string
D. Replace every subsequence of the input sequence that matches pattern with a replacement string
E. do?a) Replace all characters that matches pattern with a replacement stringb) Replace first subsequence that matches pattern with a replacement stringc) Replace all other than first subsequence of that matches pattern with a replacement stringd) Replace every subsequence of the input sequence that matches pattern with a replacement string
Answer» E. do?a) Replace all characters that matches pattern with a replacement stringb) Replace first subsequence that matches pattern with a replacement stringc) Replace all other than first subsequence of that matches pattern with a replacement stringd) Replace every subsequence of the input sequence that matches pattern with a replacement string
3.

What does public int end(int group) return?

A. offset from last character of the subsequent group
B. offset from first character of the subsequent group
C. offset from last character matched
D. offset from first character matched
Answer» B. offset from first character of the subsequent group
4.

Which of the following matches end of the string using regular expression in java?

A. \z
B. \\
C. \*
D. \Z
Answer» B. \\
5.

Which of the following matches nonword character using regular expression in java?

A. \w
B. \W
C. \s
D. \S
Answer» C. \s
6.

Which capturing group can represent the entire expression?

A. group *
B. group 0
C. group * or group 0
D. None of the mentioned
Answer» C. group * or group 0
7.

Object of which class is used to compile regular expression?

A. Pattern class
B. Matcher class
C. PatternSyntaxException
D. None of the mentioned
Answer» B. Matcher class
8.

What is the significance of Matcher class for regular expression in java?

A. interpretes pattern in the string
B. Performs match in the string
C. interpreted both pattern and performs match operations in the string
D. None of the mentioned.
Answer» D. None of the mentioned.
9.

Which of the following is not a class of java.util.regex?

A. Pattern class
B. matcher class
C. PatternSyntaxException
D. Regex class
Answer» E.
10.

WHAT_DOES_PUBLIC_INT_START()_RETURN??$

A. returns start index of the input string
B. returns start index of the current match
C. returns start index of the previous match
D. none of the mentioned
Answer» D. none of the mentioned
11.

groupCount reports a total number of Capturing groups.

A. True
B. False
Answer» B. False