不带括号和逗号打印阵列 [英] Print array without brackets and commas
问题描述
我有previously写了一个刽子手游戏在学校我的Java类。我现在正在将它移植到Android和遇到的一些问题。原始的Java程序写的所有输出到控制台。现在我必须以某种方式beutify输出,使其适合,我设计了布局。
I have previously written a Hangman game for my java class in school. I am now currently porting it to Android and have met a few problems. The original java program wrote all outputs to the console. Now i have to somehow beutify the output so that it fits the layout that i have designed.
如何打印不带括号和逗号的数组?该数组包含斜杠,并得到一个更换时,其中一个正确的字母是猜测。
How do i print an array without the brackets and commas? The array contains slashes and gets replaced one by one when the correct letter is guessed.
我使用ArrayList类的通常的ToString()函数,我的输出格式,如:[A,N,D,R,O,I,D]。我想将它打印出数组作为一个字符串。
I am using the usual .toString() function of the ArrayList class and my output is formatted like: [ a, n, d, r, o, i, d ]. I want it to simply print out the array as a single string.
这个问题似乎很简单,但我一直没能找到一个解决的办法。不使用搜索功能或者
This problems seems so simple although i haven't been able to find a solution to it. Not by using the search function either.
我填用code此位的数组:
I fill the array using this bit of code:
for(int i = 0;i<secretWordLength;i++){
hiddenArray.add(secretWord.substring(i,i+1));
publicArray.add("-");
}
和我打印出来是这样的:
And i print it like this:
final TextView currentWordView = (TextView) findViewById(R.id.CurrentWord);
currentWordView.setText(publicArray.toString());
任何帮助将AP preciated
Any help would be appreciated
推荐答案
基本上不使用 ArrayList.toString()
- 打造串起来为自己。例如:
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();
(我个人不会把变量 publicArray
时,它实际上不是一个数组,顺便说一句。)
(Personally I wouldn't call the variable publicArray
when it's not actually an array, by the way.)
这篇关于不带括号和逗号打印阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!