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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


jaid.sk
merging
1 Answer(s)      4 years and 6 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 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
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
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->
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
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
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;   
Database replication
. Following ways database replications are done: a) Snapshot replication b) Merging
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
What is JPA 2.1?
; JPA 2.1 user cab use specified fetching or merging of objects
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
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 Remove Array Element In Java
;); } System.out.println(""); //Merging array list tempArray2 and tempArray1...;); } System.out.println(""); //Merging array list tempArray3 and tempArray4
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
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
(0.00 sec) Query to create table named Emptotal which is the merging... 'Emptotal' that is the outcome merging of two table 'employee01
Advertisements
 

 

 

DMCA.com