Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Concatenate strings in Java

  • Use the + operator

public class ConcatStrings {
    public static void main(String[] args) {
        String h = "Hello";
        String w = "World";
        String full = h + " " + w;
        System.out.println(full);  // Hello World
    }
}
$ javac ConcatStrings.java
$ java ConcatStrings