merging

merging

how to merge two arrays and displaying the third array
View Answers

April 27, 2010 at 10:13 AM

Hi Friend,

Try the following code:

import java.util.*;
class MergeArray{
public static int[] merge(int []... arr) {
int arrSize = 0;
for (int[] array : arr) {
arrSize += array.length;
}
int[] result = new int[arrSize];
int j = 0;
for (int[] array : arr) {
for (int s : array) {
result[j++] = s;
}
}
return result;
}
public static void main(String[] args) {
int[] array1 = new int[5];
System.out.println("Enter 5 numbers");
Scanner input = new Scanner(System.in);
for (int i = 0; i < array1.length; i++) {
array1[i] = input.nextInt();
}
int[] array2 = new int[5];
System.out.println("Enter 5 numbers");
for (int i = 0; i < array2.length; i++) {
array2[i] = input.nextInt();
}
int M[] = (int [])merge(array1,array2);
System.out.println("Merged Array is: ");
for(int i=0;i<M.length;i++){
System.out.println(M[i]);
}

}
}

Thanks









Related Tutorials/Questions & Answers:
Merging multiple PDF files - Framework
Merging multiple PDF files  I m using the iText package to merge pdf files. Its working fine but on each corner of the merged filep there is some... the files are having different font.Please help
Merging Two Arrays Of Different Lengths
Merging Two Arrays Of Different Lengths  I have two arrays of different lengths and wants to have merged values into third. The only condition is, I want unique values in it(third array). Thanks In Advance
Advertisements
Merging of java script with servlet program
Merging of java script with servlet program  how can we merge the java script with the any servlet program for making web application intractive.Is there any program you have.\please help me to sove out this problem
Spring Collection Merging
Spring Collection Merging The merging of collection is allowed in the Spring 2.0. A parent-style like <list/>, <map/>, <set/> or <pros... collection. For collection merging you need to specify merge=true attribute
merging - Java Beginners
File Directory Merging
Merging Two Cells
Merging two cells       In this program we are going to merge two cells of an excel sheet.... In this example, we are merging the two cells into a single cell. In this example, Region(1
EMFScript
(composition, merging, audit, ...). For these manipulations, transformation languages
What is EAI?
What is EAI?       EAI stands for Enterprise Application Integration. EAI works for merging the various project application into a common programming package that can be access
Merge two list into a single list
*mergelist (struct node *p, struct node *q) { struct node *r=NULL,*temp; if (p == NULL) r = q; else if(q == NULL) r = p; else { if (p->data < q->data ) { r = p; temp = p; p = p->link; temp->
Open Source XML Diff written in Java
How To Append String In Java
PHP Addition of Array
Open Source XML Diff written in Java
arrays in java - Java Beginners
arrays in java  Hi All, I have two arrays. in this two array some name are same. I want to merge those arrays into single. But while merging I want to delete duplicate entries. How merge those arrays. Thanks, mln15584
Combining records from two or more orders files into a single ordered file is called
Combining records from two or more orders files into a single ordered file is called  Combining records from two or more orders files into a single ordered file is called? 1. Menu 2. Merging 3. Taking 4. All of the above 5
Database replication
. Following ways database replications are done: a) Snapshot replication b) Merging
merge tables in sql using union
merge tables in sql using union  How to create a new table in database by merging two tables using union function in SQL?   REATE TABLE new_table SELECT * FROM table1 UNION SELECT * FROM table2;   
PHP Array Merge Recursive
/><b>After merging two arrays the values of \$array1 is:</b><br...; string(8) "diligent" } After merging two arrays the values..._dump($array2); echo"<br/><b>After merging two arrays the values
arrays
++) { System.out.println(tempArray1[i]); } //Merging array list...(tempArray4[i]); } //Merging array list tempArray3
How to define variable in Velocity
, writer): Merge method of the Template class is used here for merging the 
How to set a variable value using velocity
for merging the VelocityContext class object to produce the output
Foreach loop with negative index in velocity
here for merging the VelocityContext class object to produce the output
How to use dollar sign in velocity
): Merge method of the Template class is used here for merging
including index in java regular expression
including index in java regular expression  Hi, I am using java regular expression to merge using underscore consecutive capatalized words e.g., "New York" (after merging "New_York") or words that has accented characters
What is JPA 2.1?
or merging of objects. The new update supports arithmetic sub-queries
Mysql Merge Statement
) Query to create table named Emptotal which is the merging of both...' that is the outcome merging of two table 'employee01' and 'employee02'.ADS
Mysql Merge
(0.00 sec) Query to create table named Emptotal which is the merging of both...' that is the outcome merging of two table 'employee01' and 'employee02'.The UNION
Mysql Merge Statement
named Emptotal which is the merging of both the table name employee01 and employee02 : The Query create a table 'Emptotal' that is the outcome merging of two
Mysql Merge
which is the merging of both the table name employee01 and employee02 : The Query create a table 'Emptotal' that is the outcome merging of two table 'employee01
How To Remove Array Element In Java
; "); } System.out.println(""); //Merging array list...(tempArray4[i]+" "); } System.out.println(""); //Merging array
Java Merge Array
Java Merge Array You all are aware of Arrays, their structure, declaration, initialization, copying etc and used them in your applications. There is one thing important regarding arrays i.e merging of arrays - add two or more arrays
SlickEdit
structures. DIFFzillaŽ provides editable dynamic differencing and merging for files
JPA 2.1 Tutorial
. Entity Graphs - allow partial or specified fetching or merging
Business Intelligence for Telecommunications
for new markets with new services. This resulted in merging and acquisition
JavaScript array merge
print the concatenated array by merging two array. Arraymerge.htmlADS
Legacy Composer
and debuggers as well as code merging and re-factoring tools. Legacy Composer
Python 3.9 Features
for dictionary update and merge operations. The | operator is used for merging
hi - Hibernate
("merging Userin instance"); try { Userin result = (Userin) getSession
VoIP Products
Group being acquired or merging with another company, the industry is in flux
Open Source Version Control
repository, all the way through to more complex features such as creating and merging
Technology What is and FAQs
for merging the various project application into a common programming package

Ads