Print array without brackets and commas

后端 未结 10 767
囚心锁ツ
囚心锁ツ 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:10

    Basically, don't use ArrayList.toString() - build the string up for yourself. For example:

    StringBuilder builder = new StringBuilder();
    for (String value : publicArray) {
        builder.append(value);
    }
    String text = builder.toString();
    

    (Personally I wouldn't call the variable publicArray when it's not actually an array, by the way.)

提交回复
热议问题