用顿号将若干个字符串分隔开

用顿号将若干个字符串分隔开

错误做法:

 String[] words
= { " a " , " b " , " c " } ;
 String word
= "" ;

 
for ( int  i = 0 ;i < words.length;i ++ )
 
{
     word
+= words[i]+ " " ;
 }


 正确做法:

 String[] words
= { " a " , " b " , " c " } ;
 String word
= "" ;

 
for ( int  i = 0 ;i < words.length;i ++ )
 
{
     
if  ( ! word.equals( "" )) 
     word
+= " " ;
     word
+= words[i];
 }




你可能感兴趣的:(用顿号将若干个字符串分隔开)