October 2017
Beginner
318 pages
7h 26m
English
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:
Read now
Unlock full access