java合併char string

2006-12-22 4:57 pm
請問如何用operator合併兩個字串
例如 a= * ; b = # ; 結果要是 *#

及 如何用operator將字串自己相加
例如 a = * ; 相加後變成 **

回答 (1)

2006-12-22 5:28 pm
✔ 最佳答案
to concate two string, just use [+] operator. try following code:

public class StrAdd
{ public static void main( String[] args )
{ String str1 = new String( "a" );
String str2 = new String( "*" );
String str3 = str1 + str2;

System.out.println( str3 );
}
}


if u want to get double for this string, just use [+=]. try following code:

public class StrDouble
{ public static void main( String[] args )
{ String str1 = new String( "*" );

str1 += str1;

System.out.println( str1 );
}
}

hope can help u


收錄日期: 2021-04-13 13:38:57
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061222000051KK00511

檢視 Wayback Machine 備份