1//Java
2String firstName = "BarackObama";
3String lastName = " Care";
4//First way
5System.out.println(firstName + lastName);
6//Second way
7String name = firstName + lastName;
8System.out.println(name);
9//Third way
10System.out.println("BarackObama" + " Care");
1//The String class includes a method for concatenating two strings :
2
3string1.concat(string2);
4This returns a new string that is string1 with string2 added to it at the end. You can also use the concat() method with string literals
5
6"My Name is".concat("Zara");
7Strings are most commonly concatenated with the "+" operator
8
9"Hello," + " world" + "!"
10Example
11public class StringDemo {
12
13 public static void main(String args[]) {
14 String string1 = "saw I was ";
15 System.out.println("Dot " + string1 + "Tod");
16 }
17}
18Some String Handling Methods
19char charAt(int index) - Returns the character at the specified index.
20int compareTo(Object o) - Compares this String to another Object.
21String concat(String str) - Concatenates the specified string to the end of this string.
22boolean equals(Object anObject) - Compares this string to the specified object.
23boolean equalsIgnoreCase(String anotherString) - Compares this String to another String, ignoring case considerations.
1//The String class includes a method for concatenating two strings :
2
3string1.concat(string2);
4This returns a new string that is string1 with string2 added to it at the end. You can also use the concat() method with string literals
5
6"My Name is".concat("Zara");
7Strings are most commonly concatenated with the "+" operator
8
9"Hello," + " world" + "!"
10Example
11public class StringDemo {
12
13 public static void main(String args[]) {
14 String string1 = "saw I was ";
15 System.out.println("Dot " + string1 + "Tod");
16 }
17}
1let myPet = 'seahorse';console.log('My favorite animal is the ' + myPet + '.'); // My favorite animal is the seahorse.