I know this question is asked before but I am really not able to find a working method I tried the method in the following link How to construct ArrayList from 2D int array? which I think is the most relevant to my case I applied the following code:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class MonteCarloSim {
private int[] ints;
public MonteCarloSim(int[] ints) {
this.ints = ints.clone();
Arrays.sort(this.ints);
}
@Override
public int hashCode() {
return Arrays.hashCode(ints);
}
@Override
public boolean equals(Object obj) {
if(obj instanceof MonteCarloSim) {
MonteCarloSim another = (MonteCarloSim) obj;
int[] original = Arrays.copyOf(another.ints, another.ints.length);
return Arrays.equals(ints, original);
} else {
return false;
}
}
@Override
public String toString() {
return Arrays.toString(ints);
}
public static void main(String arg[]){
then I determined a 2D integer array with zero, one elements having a size of 1000*20 called IncProb1 I apply the following code to remove dublicate rows:
int[][] arrays = IncProb1;
Set<MonteCarloSim> rows = new HashSet<MonteCarloSim>();
for(int[] a: arrays) {
rows.add(new MonteCarloSim(a));
}
for(MonteCarloSim row: rows) {
System.out.println(row);
}
But this doesn't work I only get one row which is [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] and this is not the solution there should be at least 300 rows not repeated. I don't know whats wrong Any help is highly appreciated Thanks in advance