Java String Handling and Regular Expressions Flashcards
7 cards from real SCJP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Java String Handling and Regular Expressions flashcards as text
Which class from java.util.regex is used to perform match operations on input strings?
Answer: Matcher
A Matcher object is created from a Pattern and is used to perform matching operations on a character sequence.
What is the output of: new StringBuilder("Hello").reverse().toString();
Answer: olleH
StringBuilder.reverse() reverses the character sequence in place and returns the same StringBuilder, so toString() produces "olleH".
What does the regular expression "^[A-Z]" match?
Answer: A string that starts with an uppercase letter
The ^ anchor asserts the start of the string, so ^[A-Z] matches a string whose first character is an uppercase letter.
What is the difference between String.equals() and String.equalsIgnoreCase()?
Answer: equals() is case-sensitive; equalsIgnoreCase() ignores letter case differences
equals() performs a case-sensitive content comparison, while equalsIgnoreCase() treats uppercase and lowercase letters as equal.
What is the output of: String.format("%05d", 42);
Answer: "00042"
%05d formats the integer with a field width of 5, padding with leading zeros, producing "00042".
Which StringBuilder method appends a String to the end of the buffer?
Answer: append()
StringBuilder.append() adds the given value to the end of the character sequence in the buffer.
What does the regex quantifier {2,5} mean?
Answer: Between 2 and 5 occurrences (inclusive)
{2,5} is a bounded quantifier meaning the preceding element must occur at least 2 and at most 5 times.
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy