I have a situation where I want to convert a string into an ArrayList THAT CONTAINS INTEGERS AND OTHER ARRAYLISTS. In my string, I can have an arbitrary number of words which I want added into the ArrayList object:
String s = "[2,5,9,8,1,[5,7],9,8,[9,6,9,8],8,9]";
I did some work:
String testdata = "[25,645,[36,65],65]";
ArrayList<Integer> arrayInt = new ArrayList<>();
try (Scanner readFile = new Scanner(testdata)) {
Pattern digitsPattern = Pattern.compile("(\\d+)");
while (readFile.hasNextLine()) {
Matcher m = digitsPattern.matcher(readFile.nextLine());
while (m.find())
arrayInt.add(Integer.valueOf(m.group(1)));
}
}
The result is:
[25, 645, 36, 65, 65]
IWhat i want is this : [25,645,[36,65],65]