3. String Manipulation & Text Validation

String Methods for QA Engineers

1. equals() & equalsIgnoreCase(): Always use .equals() instead of == for String content comparisons. 2. contains(): Validating that a banner contains an expected keyword. 3. trim(): Removing leading and trailing whitespace from UI text. 4. split(): Extracting dynamic values like order confirmation numbers.
String bannerText = "  Order #98432 placed successfully!  ";
String cleaned = bannerText.trim();
boolean hasOrder = cleaned.startsWith("Order #");
String orderId = cleaned.split("#")[1].split(" ")[0]; // "98432"

Task

  • Implement cleanAndExtractId:
  • 1. Trim the rawMessage string.
  • 2. If rawMessage starts with "ID:", return the substring following "ID:" trimmed.
  • 3. Otherwise return an empty string.
πŸ’‘Common doubts
Did you like the problem?
Lesson 3 of 38
Java
Loading code editor…
Next