How do I convert a YailList to String and replace double quotes with single quotes?

This works for me:

public static void main(String[] args) {
        System.out.println(Arrays.toString(parse(new Object[]{"\"hello\"", 1,Arrays.toString(parse(new Object[]{"\"hello\"", 1}))})));
}
 public static Object[] parse(Object[] arr){
        Object[] rArr = new Object[arr.length];
        for (int i=0;i<arr.length;i++){
            Object o = arr[i];
            if (o instanceof String){
                rArr[i] = o.toString().replaceAll("\"","'");
            }else if(o instanceof Object[]){
                Object[] innerArr = (Object[]) o;
                rArr[i] = parse(innerArr);
            }else {
                rArr[i] = o;
            }
        }
        return rArr;
 }
Output: ['hello', 1, ['hello', 1]]

@oseamiya I appreciate your efforts but there is a small flaw in your code and that's what if user inputs an Array of Object Arrays (not String Array).

2 Likes