- Add the Codota plugin to your IDE and get smart completions

private void myMethod () {Connection c =

- DataSource dataSource;dataSource.getConnection()
- String url;DriverManager.getConnection(url)
- IdentityDatabaseUtil.getDBConnection()
- Smart code suggestions by Tabnine
}

## Javadoc

Sets.cartesianProduct(ImmutableList.of(

returns a set containing six lists:

- ImmutableList.of(1, "A")
- ImmutableList.of(1, "B")
- ImmutableList.of(1, "C")
- ImmutableList.of(2, "A")
- ImmutableList.of(2, "B")
- ImmutableList.of(2, "C")

The result is guaranteed to be in the "traditional", lexicographical order for Cartesian products that you would get from nesting for loops:

for (B b0 : sets.get(0)) }}

Note that if any input set is empty, the Cartesian product will also be empty. If no sets at all are provided (an empty list), the resulting Cartesian product has one element, an empty list (counter-intuitive, but mathematically consistent).

*Performance notes:* while the cartesian product of sets of size
m, n, p is a set of size
m x n x p, its actual memory
consumption is much smaller. When the cartesian set is constructed, the
input sets are merely copied. Only as the resulting set is iterated are the
individual lists created, and these are not retained after iteration.

## Popular methods of Sets

- newHashSetCreates a mutable HashSet instance initially containing the given elements.Note: if elements are non
- newLinkedHashSetCreates a mutable LinkedHashSet instance containing the given elements in order. Note: if mutability
- newTreeSetCreates a mutable, empty TreeSet instance with the given comparator.Note: if mutability is not requi
- unionReturns an unmodifiable view of the union of two sets. The returned set contains all elements that a
- filterReturns the elements of a SortedSet, unfiltered, that satisfy a predicate. The returned set is a liv
- intersectionReturns an unmodifiable view of the intersection of two sets. The returned set contains all elements
- newHashSetWithExpectedSizeReturns a new hash set using the smallest initial table size that can hold expectedSizeelements with
- newIdentityHashSetCreates an empty Set that uses identity to determine equality. It compares object references, instea
- differenceReturns an unmodifiable view of the difference of two sets. The returned set contains all elements t
- equalsImplAn implementation for Set#equals(Object).
- hashCodeImplAn implementation for Set#hashCode().
- immutableEnumSetReturns an immutable set instance containing the given enum elements. Internally, the returned set w

## Popular in Java

- Parsing JSON documents to java classes using gson
- orElseThrow (Optional)Return the contained value, if present, otherwise throw an exception to be created by the provided s
- scheduleAtFixedRate (Timer)
- requestLocationUpdates (LocationManager)
- Window (java.awt)A Window object is a top-level window with no borders and no menubar. The default layout for a windo
- EOFException (java.io)Thrown when a program encounters the end of a file or stream during an input operation.
- BigDecimal (java.math)An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
- SQLException (java.sql)An exception that indicates a failed JDBC operation. It provides the following information about pro
- TreeSet (java.util)TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
- FileUtils (org.apache.commons.io)General file manipulation utilities. Facilities are provided in the following areas: * writing to a