

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Merge arrays into a new object array in Java
Following is the Java program to merge array into a new object array in Java −
Example
import java.util.stream.Stream; import java.util.Arrays; import java.io.*; public class Demo{ public static <T> Object[] concat_fun(T[] my_obj_1, T[] my_obj_2){ return Stream.concat(Arrays.stream(my_obj_1), Arrays.stream(my_obj_2)).toArray(); } public static void main (String[] args){ Integer[] my_obj_1 = new Integer[]{67, 83, 90}; Integer[] my_obj_2 = new Integer[]{11, 0, 56}; Object[] my_obj_3 = concat_fun(my_obj_1,my_obj_2); System.out.println("The two objects merged into a single object array : " + Arrays.toString(my_obj_3)); } }
Output
The two objects merged into a single object array : [67, 83, 90, 11, 0, 56]
A class named Demo contains the ‘concat_fun’ that takes two objects and returns the concatenated objects as output. In the main string, two integer objects are created and a third object is used to store the concatenated objects. The relevant messages are displayed on the console.
- Related Questions & Answers
- How to add two arrays into a new array in JavaScript?
- How to merge objects into a single object array with JavaScript?
- Converting array of arrays into an object in JavaScript
- Merge two sorted arrays into a list using C#
- JavaScript Converting array of objects into object of arrays
- Merge two sorted arrays in Java
- Merge k sorted arrays in Java
- How to merge multiple files into a new file using Python?
- C# program to merge two sorted arrays into one
- Converting two arrays into a JSON object in JavaScript
- How to merge an array with an object where values are arrays - JavaScript
- Digits of element wise sum of two arrays into a new array in C++ Program
- map() array of object titles into a new array based on other property value JavaScript
- Zip two arrays and create new array of object in a reshaped form with MongoDB
- How to add a new object into a JavaScript array after map and check condition?
Advertisements