The input stream can be parsed using String::split and Stream API:
- get rows splitting by comma between a pair of
},{
- remove redundant curly brackets using
String::replaceAll
- for each row, split by comma, convert numbers to int
Stream::mapToInt and get array
- collect to multidimensional array with
Stream::toArray
String arrContent = "{{0,1},{2,3},{4,5}}";
int[][] arr = Arrays.stream(arrContent.split("\\}\\s*,\\s*\\{")) //1
.map(s -> s.replaceAll("[{}]", "")) //2
.map(s -> Arrays.stream(s.split("\\s*,\\s*")) //3
.mapToInt(Integer::parseInt).toArray()
)
.toArray(int[][]::new); //4
System.out.println(Arrays.deepToString(arr));
Output
[[0, 1], [2, 3], [4, 5]]
Another approach could be to use JSON parser, however, initial input string needs to be modified to become a valid JSON array (curly brackets {} have to be replaced with the square ones [] using simpler String::replace(char old, char rep)):
String arrContent = "{{0,1},{2,3},{4,5}}";
ObjectMapper om = new ObjectMapper();
int[][] arr = om.readValue(
arrContent.replace('{', '[')
.replace('}', ']'),
int[][].class);
System.out.println(Arrays.deepToString(arr));
// output
[[0, 1], [2, 3], [4, 5]]
String, which is rather complicated in this case. If you have the possibility to change the file's content to json, using a json parser will be the quickest solution.