Print array without brackets and commas

后端 未结 10 785
囚心锁ツ
囚心锁ツ 2020-11-29 23:28

I\'m porting a Hangman game to Android and have met a few problems. The original Java program used the console, so now I have to somehow beautify the output so that it fits

10条回答
  •  情话喂你
    2020-11-30 00:09

    Replace the brackets and commas with empty space.

    String formattedString = myArrayList.toString()
        .replace(",", "")  //remove the commas
        .replace("[", "")  //remove the right bracket
        .replace("]", "")  //remove the left bracket
        .trim();           //remove trailing spaces from partially initialized arrays
    

提交回复
热议问题