String Methods
In this lesson, we will see the functionality of inbuilt methods in String Class.
Concatenation
Java provides special support for the concatenation of multiple Strings. Concatenation is referred to as the joining of two or more Strings. This is done by the use of the +
operator. The code below shows an example of both.
Did you know? The interesting thing is that the
+
operator can be used to not only join a String with other Strings but also join Strings with other types of objects.
Press + to interact
class concat {public static void main(String[] args) {String one = "Hello";String two = " World";int number = 10;// concatenating two stringsSystem.out.println(one + two);//concatenating a number and stringSystem.out.println(one + " " + number);//saving concatenated string and printingString new_string = one + two + " " + number;System.out.println(new_string);}}
Note: Keep in mind that using the + operator will first convert the number or other objects to String type and then ...