Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


jaid.sk
merging
1 Answer(s)      4 years and 4 months ago
Posted in : Java Beginners


how to merge two arrays and displaying the third array

Advertisement
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 Two Cells
Merging two cells       In this program we are going to merge two cells of an excel sheet... are merging the two cells into a single cell. In this example, Region(1,(short)1,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->
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
); echo"<br/><b>After merging two arrays the values of \$array1...; string(8) "diligent" } After merging two arrays the values... merging two arrays the values of \$array1 is:</b><br/>"
How to use dollar sign in velocity
): Merge method of the Template class is used here for merging
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
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?
; JPA 2.1 user cab use specified fetching or merging of objects
Mysql Merge Statement
(0.00 sec) Query to create table named Emptotal which is the merging... 'Emptotal' that is the outcome merging of two table 'employee01
Mysql Merge
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
Mysql Merge Statement
to create table named Emptotal which is the merging of both the table name...' that is the outcome merging of two table 'employee01' and 'employee02'. mysql> CREATE TABLE
Mysql Merge
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
How To Remove Array Element In Java
;); } System.out.println(""); //Merging array list tempArray2 and tempArray1...;); } System.out.println(""); //Merging array list tempArray3 and tempArray4
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
- allow partial or specified fetching or merging of objects. JPQL
Business Intelligence for Telecommunications
with new services. This resulted in merging and acquisition of different
JavaScript array merge
the concatenated array by merging two array. Arraymerge.html  <html>
Legacy Composer
editors, wizards, builders and debuggers as well as code merging and re
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
 

 

 

DMCA.com