Which method in AssertJ is used to check if a string starts with a specific prefix?

Which method in AssertJ is used to check if a string starts with a specific prefix?

A) startsWith()
B) beginsWith()
C) hasPrefix()
D) starts()

Answer:

A) startsWith()

Explanation:

The startsWith() method in AssertJ is used to assert that a string starts with a specific prefix. It verifies that the string begins with the specified sequence of characters.

For example:


import static org.assertj.core.api.Assertions.assertThat;

String message = "Hello, World!";

assertThat(message).startsWith("Hello");

In this example, the startsWith() method asserts that the string message starts with the prefix “Hello”.

Reference links:

https://www.javaguides.net/p/top-java-libraries.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top