I am trying to create every possible unique combination of elements.
Ex: item1, item2, item3
Combinations:
item1+item2+item3
item1+item2
item1+item3
item2+item3
item1
item2
item3
I can’t figure out how to solve this?
for(int i=0;i<size;i++){
for(int j=i+1;j<size;j++){
System.out.println(list.item(i)+list.item(j));
}
}
The above code certainly works for the entire unique combination of the two elements. But not for a pair of three elements, etc.
source
share