Q:

Ruby program to concatenate two arrays

belongs to collection: Ruby Arrays Programs

0

In this program, we will concatenate two arrays using the "+" operator and print the resulting array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to concatenate two arrays is given below. The given program is compiled and executed successfully.

#Ruby program to concatenate two arrays

arr1 = ["GODs","RAM","KRISHNA","SHIV"];
arr2 = ["COMPANY","HCL","TCS","WIPRO"];

arr3 = arr1 + arr2;

print "Concatenated array:\n#{arr3}";

Output:

Concatenated array:
["GODs", "RAM", "KRISHNA", "SHIV", "COMPANY", "HCL", "TCS", "WIPRO"]

Explanation:

In the above program, we created 2 arrays arr1arr2. Then we concatenated both arrays using the "+" operator and assigned the result to the arr3 and printed the result.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby Arrays Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Ruby program to find the uncommon elements from tw... >>
<< Ruby program to demonstrate the assoc() method...