Based on your comments you already have a method that computes all permutations of a given input, lets call this method permutate
, it takes a String
and gives a String[]
.
Now you want, from all that permutations, discard the ones that are lexicographically smaller or equals to the given input. In the end you want a collection that only contains lexicographically greater permutations.
The only thing we now need is how do we compare String
s lexicographically? But this is rather easy as String
s already offer such a method, it is called compareTo
(here is the official documentation). You use it with first.compareTo(second)
and it returns a negative, positive or zero value based on if the first String
is lexicographically smaller, greater or equals to the second String
.
So we just iterate the resulting permutations and check with compareTo
which elements need to be discarded and which we keep.
Here is a snippet:
String input = "abc";
String[] allPermutations = permutate(input); // Contains [a, b, c, ab, ac, bc, abc]
ArrayList<String> permutationsToKeep = new ArrayList<>();
for (String permutation : allPermutations) {
if (permutation.compareTo(input) > 0) {
// Permutation is lexicographically greater than input, keep it
permutationsToKeep.add(permutation);
}
}
// permutationsToKeep now contains your desired result
// [b, c, ac, bc]