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

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:

主站蜘蛛池模板: 吉首市| 行唐县| 利川市| 遂川县| 临猗县| 喀喇| 怀安县| 广州市| 石嘴山市| 郯城县| 乐陵市| 东安县| 长武县| 临安市| 旬阳县| 鲁甸县| 十堰市| 靖远县| 搜索| 辉南县| 石林| 湟中县| 英山县| 莲花县| 民丰县| 卢氏县| 清原| 九江市| 七台河市| 安国市| 博爱县| 收藏| 宁南县| 永泰县| 扬中市| 榆树市| 无棣县| 克山县| 宁陵县| 崇阳县| 宜城市|