集册 Java实例教程 Java String Concat

Java String Concat

欢马劈雪     最近更新时间:2020-01-02 10:19:05

474
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
Java String Concat

/**来自 
 n o w    j a v a  . c o m**/

public class Main {

        public static void main(String args[]){

                String str1 = "Hello";

                String str2 = " World";

               

                //1. Using + operator

                String str3 = str1 + str2;

                System.out.println("String concat using + operator : " + str3);

               

                //2. Using String.concat() method

                String str4 = str1.concat(str2);

                System.out.println("String concat using String concat method : " + str4);

               

                //3. Using StringBuffer.append method

                String str5 = new StringBuffer().append(str1).append(str2).to
展开阅读全文