Contains
Contains is a membership-query operation that reports whether a specified value, key, element, or substring occurs in a container or collection.
Clojure: The Essential Reference
.contains is a Java Collection or String method that tests whether a collection contains an element or a string contains a substring.
- How it is used
- Tests vector value membership or string substring presence where Clojure’s `contains?` would answer a different question.
- How deep it goes
- Shows calls and results, including an unsupported map call, without detailing Java method implementations.
- Examples
- Compares value and index checks on a vector, then tests a string substring and an unsupported map call.
- What you can do after
- Apply it via Java interop to check vector values or string substrings without confusing the result with `contains?`.
Read how Clojure: The Essential Reference explains contains →
100 Java Mistakes and How to Avoid Them
Collection.contains is the Java Collection interface method that tests whether a collection contains an object equal to a specified value.
- How it is used
- Tests collection membership while exposing type-mismatch and null-handling mistakes that often produce silent failures.
- How deep it goes
- Explains the Object parameter, varargs inference, semantic type mismatches, null policies, and static-analysis support.
- Examples
- Uses primitive arrays, File-versus-Path collections, nullable searches, and List.of or Set.of migrations.
- What you can do after
- Diagnose false membership results, guard nullable arguments, expose inferred types, and interpret relevant analyzer warnings.
Read how 100 Java Mistakes and How to Avoid Them explains contains →
Related concepts
- findalternative to · A find operation searches a collection for the first element or entry matching a value or predicate and returns it, or indicates that no match exists.
- binary searchuses · Binary search is an algorithm that locates a target or boundary in an ordered collection by repeatedly comparing with a midpoint and halving the remaining search range.
- extendalternative to · extend is a Ruby method that adds the instance methods of one or more modules to a particular object's singleton class.
- Objectuses · java.lang.Object is the root class of Java’s reference-type hierarchy and defines methods inherited by Java reference types.
- instance_methodproduces · instance_method is a Ruby class method that returns an unbound method object for an instance method.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

