我请检查下面的代码。
我可以理解未分配 String s1 ,因此即使使用 concat(string) 方法,它也会提供原始输出。
而且,在 String s2 的情况下,没有分配变量但串联工作。
有人可以解释一下吗?
package com.stringconcat.main;
public class StringConcat {
public static void main(String[] args) {
String s1 = "Hello";
s1.concat(" World");
System.out.println("String s1 output: " + s1);
String s2 = "Hello" /*s1*/;
System.out.println("String s2 output: " + s2.concat(" World"));
}
}
输出为: String s1 输出:Hello String s2 输出:Hello World
噜噜哒
繁星淼淼
小唯快跑啊
相关分类