import static org.hamcrest.Matchers.*; import static org.hamcrest.MatcherAssert.*; Listnames = Arrays.asList("Alice", "Bob", "Charlie"); assertThat(names, hasItem("Bob")); assertThat(names, hasItem("Bob", createIndex(1)));
import static org.hamcrest.Matchers.*; import static org.hamcrest.MatcherAssert.*; int x = 10; assertThat(x, allOf(greaterThan(5), lessThan(15)));This code verifies that the integer variable "x" is greater than 5 and less than 15. The Hamcrest library is usually included as a dependency in testing frameworks such as JUnit or TestNG, so it is not typically added directly as a package in a Java project.