โ† All SCJP Flashcard Decks

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
  1. What is the result of the following code? String s = "Hello"; s.concat(" World"); System.out.println(s);

    Answer: Hello

    String objects are immutable; concat() returns a new String but the result is not assigned back to s, so s remains "Hello".

  2. Which of the following creates a String object in the string pool?

    Answer: String s = "hello"

    String literals (String s = "hello") are stored in the string pool, while using new String() always creates an object on the heap.

  3. What does the == operator compare when used between two String objects?

    Answer: The reference (memory address) of the objects

    == compares object references, not content; use equals() to compare String content.

  4. Which class provides a thread-safe, mutable sequence of characters?

    Answer: StringBuffer

    StringBuffer is synchronized, making it thread-safe, whereas StringBuilder is faster but not thread-safe.

  5. What is the output of: System.out.println("abc".indexOf('c'));

    Answer: 2

    indexOf() returns the zero-based index; 'a' is at 0, 'b' at 1, 'c' at 2.

  6. What is printed by: System.out.println("Hello World".substring(6));

    Answer: World

    substring(6) returns characters from index 6 to the end; index 6 is 'W', yielding "World".

  7. Which method correctly checks whether a String starts with a given prefix?

    Answer: startsWith()

    The correct method name is startsWith(), which returns true if the string begins with the specified prefix.

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