Java examples for Language Basics:String
Combine two strings by using the plus sign + as a concatenation operator.
public class Main { public static void main(String[] args) { String hello = "Hello, "; String world = "World!"; String greeting = hello + world; System.out.println(greeting); }/*from ww w .j a v a 2s .co m*/ }
You can concatenate a string literal along with the string variables.
For example:
public class Main { public static void main(String[] args) { String hello = "Hello"; String world = "World!"; String greeting = hello + ", " + world; System.out.println(greeting); }/*ww w.jav a2 s. c o m*/ }