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

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:

主站蜘蛛池模板: 沈丘县| 沂水县| 靖宇县| 邵东县| 万全县| 绵竹市| 镶黄旗| 文登市| 嘉善县| 和田市| 类乌齐县| 九寨沟县| 奈曼旗| 农安县| 博野县| 梅河口市| 泗水县| 乐业县| 松滋市| 华容县| 龙岩市| 朔州市| 古交市| 疏勒县| 清流县| 商都县| 错那县| 桂平市| 内乡县| 黄山市| 金塔县| 广元市| 科技| 开江县| 芦山县| 依兰县| 高陵县| 牡丹江市| 阜城县| 法库县| 远安县|