5 ways of String Concatenation in Java

In this tutorial, we will discuss about string concatenation in java. Although there can be number of ways for concatenating strings, we will discuss 5 most important and widely used . Take a look at below example of how string concatenation works:

Input: “Hello” and “World”
Output: “HelloWorld”

Input: “1234” and “5678”
Output: “12345678”

Read Also : 5 Ways to Reverse a String in Java with Example

Points to Keep in Mind Before attempting the Solution :

 1. String is immutable so once it is created in memory we will not be able to modify it rather than assigning new String. StringBuffer and StringBuilder are mutable, so once it is created , modifications can be done later.

 2. The first argument of String.join() method is delimiter used to join strings and there can any number of string arguments starting from second argument.

5 Difference between Sleep and Wait method with Example

Today we will share the difference between sleep and wait method in java . This is one of the most popular question of Threads topic for the java beginners. Both sleep() and wait() methods are most widely used methods in Thread programming in Java.

Read Also :  Difference between implements Runnable and extends Thread in Java

Difference between Sleep and Wait method in Java

1.  Class  belongs :  The wait() method belongs to java.lang.Object class, thus can be called on any Object. The sleep() method belongs to java.lang.Thread class, thus can be called on Threads.

2. Context :  The wait() method can only be called from Synchronized context i.e. using synchronized block or synchronized method. The sleep() method can be called from any context.