我正在打印一個數組,但我只想顯示數字。我想從String
中刪除括號和逗號(只留下數字)。到目前爲止,我已經能夠刪除逗號,但我正在尋找一種方法爲replaceAll
方法添加更多參數。替換字符串中的多個字符
如何刪除括號和逗號?
cubeToString = Arrays.deepToString(cube);
System.out.println(cubeToString);
String cleanLine = "";
cleanLine = cubeToString.replaceAll(", ", ""); //I want to put all braces in this statement too
System.out.println(cleanLine);
輸出是:
[[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5]]
[[0000][1111][2222][3333][4444][5555]]
'cubeToString.replaceAll(「\\ d 「,」「)' – 4castle