Home »
Ruby Tutorial »
Ruby Programs
Ruby program to concatenate the strings using the << operator
Last Updated : December 15, 2025
Problem Solution
In this program, we will create three strings. Then we will concatenate the strings using the "<<" operator and print the result.
Program/Source Code
The source code to concatenate the strings using the "<<" operator is given below. The given program is compiled and executed successfully.
# Ruby program to concatenate the
# strings using "<<" operator
str1 = "Hello ";
str2 = "how ";
str3 = "are you. ";
str1 << str2 << str3;
print str1;
Output
Hello how are you.
Explanation
In the above program, we created three strings str1, str2, str3, that are initialized with "Hello ", "how ", "are you ". Then we concatenated the strings using the "<<" operator and printed the result.
Ruby Strings Programs »
Advertisement
Advertisement