Java Strings

Concatenation

Java String Concatenation

Strings can be joined together by using the + operator. We refer to this as concatenation:

Example

				
					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 (” “).

Example

				
					String firstName = "John ";
String lastName = "Doe";
System.out.println(firstName.concat(lastName));
				
			
Share this Doc

Concatenation

Or copy link

Explore Topic