import java.util.ArrayList;
public class Testing {
public static void main(String[] args) {
ArrayList<Double> valid = new ArrayList<Double>();
ArrayList<Double> result = new ArrayList<Double>();
valid.add(0.05);
valid.add(0.05);
valid.add(0.1);
getSum(valid, result, 0, 0);
System.out.println(result);
}
public static void getSum(ArrayList<Double> valid, ArrayList<Double> result, int start, double sum) {
if (valid.size() == start) {
result.add(sum);
return;
}
double value = sum + valid.get(start);
getSum(valid, result, start + 1, value);
getSum(valid, result, start + 1, sum);
}
}
I want to not even enter the duplicates into the result arrayList, as removing duplicates after will result in not enough memory, as the result arrayList gets too big too fast. How do I do this?
Edit: A hashset suffices.