In Java, using the following function for a huge matrix X to print its column-distinct elements:
// create the list of distinct values List va
You can use ArrayList.clear(); this keep address ArrayList in memory, without garbage collector effect on this address.
ArrayList.clear();