可能重複:
The most sophisticated way for creating comma-separated Strings from a Collection/Array/List?獨立的字符由逗號的Java
所有字符應該用逗號除了最後一個字符分開。
輸出示例: 「以前的字符猜測:A,B,C,X」 或 「猜上一個人物:一個」
繼承人我有:
ArrayList<Character> charsGuessed = new ArrayList<Character>();
//takes in char guess from user
char guess=getCharacterGuess(in);
//adds char guessed to array
charsGuessed.add(guess);
int size=charsGuessed.size();
System.out.print("Previous characters guessed: ");
for(int i=0; i<size; i++)
{
if(i<=size-1)
{
System.out.print(charsGuessed.get(i) + " ");
}
else
{
System.out.print("," + " " + charsGuessed.get(i));
}
}
什麼問題? –
http://stackoverflow.com/questions/205555/the-most-sophisticated-way-for-creating-comma-separated-strings-from-a-collectio可能有幫助 – andyb
你應該改善你的問題的細節。所以一條線......真的嗎? – MUG4N