1. 程式人生 > >java中concat()方法的使用

java中concat()方法的使用

concat()方法介紹:

將幾個字串連線到一起。
例如:
    s = s.concat(str1);//將字串str1接到字串s後面
    s = s.concat(str2);//將字串str1接到字串s後面

程式碼:

public class Test {

     public static void main(String[] args){
    	 
    	 String s = "厲害了,";
    	 String str1 = "我的";
    	 String str2 = "國!";
    	 
    	 s = s.concat(str1);//將字串str1接到字串s後面
    	 s = s.concat(str2);//將字串str1接到字串s後面
    	 
    	 System.out.println(s);

     }
       
}

執行結果:

厲害了,我的國!