Fastest way to recreate the ArrayList in a for loop
===

In Java, using the following function for a huge matrix X to print its column-distinct elements:

    // create the list of distinct values
    List<Integer> values = new ArrayList<Integer>();
    
    // X is n * m int[][] matrix
    for (int j = 0, x; j < m; j++) {
    	values.clear();
    	for (int i = 0; i < n; i++) {
    		x = X[i][j];
    		if (values.contains(x)) continue;
    		System.out.println(x);
    		values.add(x);
    	}
    }

First I iterate by columns (index j) and inside by rows (index i).

I'm wondering about the values array. Would it be faster to use `values = new ArrayList<Integer>();` or `values = null` instead of `values.clear()` ?

Please take my question seriously, because in the code this function will be called million times for different matrices, so the code should be optimized to meet the performance requirements.

Thank you for understanding.