1
class CombinationIterator {3
private Queue<String> allCombinations;5
public CombinationIterator(String characters, int combinationLength) {6
this.allCombinations = new LinkedList<>();7
generateAllCombinations(characters, 0, combinationLength, new StringBuilder());10
private void generateAllCombinations(11
String characters, int index, int combinationLength, StringBuilder currentString) {13
if (currentString.length() == combinationLength) {14
this.allCombinations.offer(currentString.toString());18
for (int i = index; i < characters.length(); i++) {19
currentString.append(characters.charAt(i));20
generateAllCombinations(characters, i + 1, combinationLength, currentString);21
currentString.deleteCharAt(currentString.length() - 1);25
public String next() {26
return this.allCombinations.poll();29
public boolean hasNext() {30
return !this.allCombinations.isEmpty();