×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

Ruby program to concatenate two arrays

Last Updated : December 15, 2025

Problem Solution

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

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 arr1, arr2. Then we concatenated both arrays using the "+" operator and assigned the result to the arr3 and printed the result.

Ruby Arrays Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.