String类的 concat()方法将指定的字符串连接到该字符串的末尾。
import java.lang.*; public class StringDemo { public static void main(String[] args) { //打印str1- String str1 = "self"; System.out.println(str1); //打印与str1串联的str2- String str2 = str1.concat(" learning"); System.out.println(str2); //打印与str2(和str1)串联的str3- String str3 = str2.concat(" center"); System.out.println(str3); } }
输出结果
self self learning self learning center