官术网_书友最值得收藏!

The concatenation operator

Another thing strings can do, which most Java classes cannot, is make use of the addition sign (+) operator. If we declare three strings (say, s1, s2, and s3), we can set the value of our third string to be one string plus another string. We can even add a string literal into the mix. Then, we print s3:

package stringsinjava; 
 
public class StringsInJava { 
    
    public static void main(String[] args) { 
        char c = 'c'; 
        String s1 = "stringone"; 
        String s2 = "stringtwo"; 
        String s3 = s1+s2+"LIT"; 
        System.out.println(s3); 
    } 
} 

When we run this program, we'll see these three strings added together in much the manner that we would expect:

主站蜘蛛池模板: 乌恰县| 长葛市| 剑川县| 合肥市| 泰宁县| 莎车县| 桂林市| 阜新市| 莎车县| 栾川县| 兴城市| 荥经县| 绥化市| 兴隆县| 兰考县| 荃湾区| 乐清市| 西藏| 沈丘县| 长治市| 夏邑县| 湾仔区| 梅河口市| 九江县| 安顺市| 贡嘎县| 北川| 枣阳市| 普安县| 江津市| 正安县| 岑巩县| 汉寿县| 六枝特区| 蓬安县| 永泰县| 农安县| 东港市| 沾化县| 卢湾区| 锦州市|