Given a string (for example: a?bc?def?g), write a program to  generate all the possible strings by replacing ? with 0 and 1. Example: Input : a?b?c? Output: a0b0c0, a0b0c1, a0b1c0, a0b1c1, a1b0c0, a1b0c1, a1b1c0, a1b1c1.I have developed a program as shown below but please advise if something more efficiently can be done.public class ReplaceQuestionMark {    public ArrayList<String> replace(String target){        return replaceHelper(target, target.length()-1);    }    public ArrayList<String> replaceHelper(String target, int to){        char c = target.charAt(to);        if (to == 0){            ArrayList<String> res = new ArrayList<String>();            if (c == '?'){                res.add(0);                res.add(1);            }            else{                res.add(c+);            }            return res;        }        ArrayList<String> res = new ArrayList<String>();        ArrayList<String> preRes = replaceHelper(target, to-1);        if (c == '?'){            for (String token: preRes){                res.add(token + 0);                res.add(token + 1);            }        }        else{            for (String token: preRes){                res.add(token + c);            }        }        return res;    }    public static void main(String[] args){        ReplaceQuestionMark rqm = new ReplaceQuestionMark();        ArrayList<String> res = rqm.replace(a?b?c?);        for (String s: res){            System.out.println(s);        }    }}
Replacing the occurence of the character in string
java;strings