Generate Cartesian product of List in Java My code, which generates Cartesian product of all lists given as arguments:

public static &lt;T&gt; List&lt;List&lt;T&gt;&gt; cartesianProduct(List&lt;T&gt;... lists) {

    List&lt;List&lt;T&gt;&gt; product = new ArrayList&lt;List&lt;T&gt;&gt;();

    for (List&lt;T&gt; list : lists) {

        List&lt;List&lt;T&gt;&gt; newProduct = new ArrayList&lt;List&lt;T&gt;&gt;();

        for (T listElement : list) {

            if (product.isEmpty()) {

                List&lt;T&gt; newProductList = new ArrayList&lt;T&gt;();
                newProductList.add(listElement);
                newProduct.add(newProductList);
            } else {

                for (List&lt;T&gt; productList : product) {

                    List&lt;T&gt; newProductList = new ArrayList&lt;T&gt;(productList);
                    newProductList.add(listElement);
                    newProduct.add(newProductList);
                }
            }
        }

        product = newProduct;
    }

    return product;
}


Can this code be simplified?
You should read about the diamond operator.  You don't need to write the types on the right hand side in some circumstances.
I avoid varargs because they confuse the type system.  My guess is that you are not using an IDE because mine (Netbeans) flags both the diamond operators and the varargs.
You can indeed shorten your code because you don't really need to do a conditional check on the empty list if you start with the right conditions:

public static &lt;T&gt; List&lt;List&lt;T&gt;&gt; computeCombinations2(List&lt;List&lt;T&gt;&gt; lists) {
    List&lt;List&lt;T&gt;&gt; combinations = Arrays.asList(Arrays.asList());
    for (List&lt;T&gt; list : lists) {
        List&lt;List&lt;T&gt;&gt; extraColumnCombinations = new ArrayList&lt;&gt;();
        for (List&lt;T&gt; combination : combinations) {
            for (T element : list) {
                List&lt;T&gt; newCombination = new ArrayList&lt;&gt;(combination);
                newCombination.add(element);
                extraColumnCombinations.add(newCombination);
            }
        }
        combinations = extraColumnCombinations;
    }
    return combinations;
}


Note that the scanning order changed: the first element stays fixed until all other combinations of the other elements are exhausted.  I prefer that order actually.
It think it would be cleaner to split this in two methods.  There is a sub-task of adding one list of elements to an existing set of combinations and the main task which must call the sub-task on all lists: 

public static &lt;T&gt; List&lt;List&lt;T&gt;&gt; computeCombinations3(List&lt;List&lt;T&gt;&gt; lists) {
    List&lt;List&lt;T&gt;&gt; currentCombinations = Arrays.asList(Arrays.asList());
    for (List&lt;T&gt; list : lists) {
        currentCombinations = appendElements(currentCombinations, list);
    }
    return currentCombinations;
}


and the sub-task (using Java 8):

public static &lt;T&gt; List&lt;List&lt;T&gt;&gt; appendElements(List&lt;List&lt;T&gt;&gt; combinations, List&lt;T&gt; extraElements) {
    return combinations.stream().flatMap(oldCombination
            -&gt; extraElements.stream().map(extra -&gt; {
                List&lt;T&gt; combinationWithExtra = new ArrayList&lt;&gt;(oldCombination);
                combinationWithExtra.add(extra);
                return combinationWithExtra;
            }))
            .collect(Collectors.toList());
}


Actually, for this method, Java 8 does not make it shorter and makes it less readable than the old style.  I am leaving it nonetheless so you (and others) can get more familiar with Java 8. 
Minor point: I think you use too many blank lines in your code.