You have to return from your function when string
's length is 0
. Right now you're just printing your prefix
and then the line:
subset(prefix + string.charAt(0), string.substring(1));
is executed, which raises StringIndexOutOfBoundsException
because you're calling .substring(1)
on an empty string.