Sunday, 29 June 2014

How to Concatenate Strings in Java

This example shows how to concatenate strings i.e. how to join them together:

andrew@UBUNTU:~/Java$ cat prog38.java
public class prog38
{
public static void main (String args[])
  {
  String first_name = "Andrew";
  String surname = "Reid";
  String full_name = first_name + " " + surname;
  System.out.println ("full_name = " + full_name);
  }
}
andrew@UBUNTU:~/Java$ javac prog38.java
andrew@UBUNTU:~/Java$ java prog38
full_name = Andrew Reid
andrew@UBUNTU:~/Java$