Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for your Java exam with our ultimate quiz based on 'Thinking in Java'. Engage with expertly crafted questions that enhance your learning process. Perfect for Java enthusiasts looking to solidify their knowledge!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


How is the method substring() different from subSequence() in String class?

  1. substring() returns a string while subSequence() returns a CharSequence

  2. There's no difference

  3. subSequence() is deprecated

  4. substring() allows for regular expression patterns

The correct answer is: substring() returns a string while subSequence() returns a CharSequence

The method substring() returns a modified copy of the original string, while subSequence() returns a portion of the original string without modifying it. This allows for easier manipulation of strings without affecting the original. Option B is incorrect because there is a clear difference between the two methods. Option C is incorrect because subSequence() is not deprecated, but it may be less commonly used compared to substring(). Option D is incorrect because substring() does not specifically allow for regular expression patterns, although it can be used with them.