Java Strings
Strings can be joined together by using the + operator. We refer to this as concatenation:
String firstName = "John";
String lastName = "Doe";
System.out.println(firstName + " " + lastName);
Observe that in order to provide a space between firstName and lastName while printing, we have added an empty text (” “).
String firstName = "John ";
String lastName = "Doe";
System.out.println(firstName.concat(lastName));
CodingAsk.com is designed for learning and practice. Examples may be made simpler to aid understanding. Tutorials, references, and examples are regularly checked for mistakes, but we cannot guarantee complete accuracy. By using CodingAsk.com, you agree to our terms of use, cookie, and privacy policy.
Copyright 2010-2024 by Refsnes Data. All Rights Reserved.