- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to concatenate two arrays in java?
One way of doing it is, create an array of length equals to the sum of lengths of the two arrays and, add elements of both arrays to it one by one.
Example
public class HelloWorld { public static void main(String[] args) { int[]a = {1,2,3,4}; int[]b = {4,16,1,2,3,22}; int[]c = new int[a.length+b.length]; int count = 0; for(int i = 0; i<a.length; i++) { c[i] = a[i]; count++; } for(int j = 0;j<b.length;j++) { c[count++] = b[j]; } for(int i = 0;i<c.length;i++) System.out.print(c[i]+" "); } }
Output
1 2 3 4 4 16 1 2 3 22
- Related Articles
- Java Program to Concatenate Two Arrays
- How can I concatenate two arrays in java
- How to concatenate Two Arrays in C#?
- Python Program to Concatenate Two Arrays
- The easiest way to concatenate two arrays in PHP?
- How to concatenate two strings using Java?
- How to compare two arrays in Java?
- Java Program to Concatenate Two List
- How to concatenate lists in java?
- How to concatenate two strings in C#?
- How to concatenate two strings in Python?
- How to concatenate two slices in Golang?
- How to concatenate two strings in Golang?
- How do I concatenate or Merge Arrays in Swift?
- How to find the intersection of two arrays in java?

Advertisements