I am looking to created an ArrayList that is the exact replica of a String representation of a nested list. So given "[4, 9, 12, [1,2,3], [5,6,10], [11,12]]" the list would be [4,9,12,[1,2,3],[5,6,10],[11,12]].
static int position =0;
public static ArrayList stringToList(String input) {
List<ArrayList> parsedList = new ArrayList<>();
while(position < input.length()){
char element = input.charAt(position++);
if(element == '['){
parsedList.add(parseListsToString(input));
}else if(element==']'){
break;
}else if(element==','){}
else{
parsedList.add(element);
}
}
return parsedList;
}
I have tried declaring parsedList as: ArrayList(ArrayList) (which allows for recursion) and ArrayList(Integer) (which doesn't allow for recursion). And in the current code that I submitted about is obviously wrong because parsedList is an incorrect return type because its not an ArrayList.
I believe that my method in going about the problem is right just that my understanding of ArrayList is lacking and that is where I need help. So any suggestions would be appreciated! Thanks in advance!
ArrayListcan hold a both anIntegerand aList?