Question: merging

Ads

 
 
 

Share on Google+Share on Google+

jaid.sk
merging
1 Answer(s)      7 years ago
Posted in : Java Beginners
how to merge two arrays and displaying the third array
Ads
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

Ads









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
Tutorials   
Java Spring Hibernate Struts Training Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile? How to create first Java Program? Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include?

Ads

 
Advertisement null

Ads