public static CharSequence concat ( CharSequence ... text ) { if ( text . length == 0 ) { return "" ; } if ( text . length == 1 ) { return text [ 0 ] ; } boolean spanned = false ; for ( int i = 0 ; i < text . length ; i ++ ) { if ( text [ i ] instanceof Spanned ) { spanned = true ; break ; } } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < text . length ; i ++ ) { sb . append ( text [ i ] ) ; } if ( ! spanned ) { return sb . toString ( ) ; } SpannableString ss = new SpannableString ( sb ) ; int off = 0 ; for ( int i = 0 ; i < text . length ; i ++ ) { int len = text [ i ] . length ( ) ; if ( text [ i ] instanceof Spanned ) { copySpansFrom ( ( Spanned ) text [ i ] , 0 , len , Object . class , ss , off ) ; } off += len ; } return new SpannedString ( ss ) ; }
Returns a CharSequence concatenating the specified CharSequences retaining their spans if any .