How can you add elements of two arrayLists in java?

Ads
 

How can you add elements of two arrayLists in java?

if you have an arrayList of tempArr = [hi, my, name, is, john] and another arrayList of tempArray2 = [a, b, c, d, e] and you want it to result in newArr = [hi a, my b, name c, is d, john e] how do you go about that?

View Answers

April 4, 2011 at 3:04 PM

public class CombineArrays {
 public static void combineValues(int length, int[] array1, int[] array2){      
        int col = 2;
        int k = 1;
        int[][] array = new int[length][col];   


        for( int i = 0; i < length; i++ )
        {
            for( int j = 0; j < 1; j++ )
            {
                array[i][j] = array1[i];
            }
            array[i][k] = array2[i];
        }

        print( array );
            }

public static void print(int[][]array){
    for (int i=0 ; i < array.length ; i++)
        {     System.out.println();
            for  (int j=0 ; j < array[i].length ; j++){
                System.out.print(array[i][j]+" ");
                  }
        }
}
    public static void main(String[] args)
     {
      int arr1[] = {7,7,3};
      int arr2[] = {4,6,2};
      combineValues(3,arr1,arr2);
     }
    }

Ads









Related Tutorials/Questions & Answers:
How can you add elements of two arrayLists in java?
Add two number in java
Advertisements
How to add two numbers in Java?
Add two big numbers
How to add two calendars on the same html page
Java2
How do you add a numerical value to a regex
how can i add hibernate plugin to eclipse?
How would you read in and add all this into a list?
how i can print the elements before a spicific value in array queue?
how to add new column before two column in sql.
how to add new column before two column in sql.
how to add new column before two column in sql.
how to add new column before two column in sql.
how can you say java is secure
how can I great two user and password in C++?
how can I great two user and password in C++?
How can you tell a fake data scientist?
How many qusetions can you ask?
Can you tell me how it worked?
Javah
JavaScript Add Element to Array
how can add new line character into ajax response for java
how can add new line character into ajax response for java
ModuleNotFoundError: No module named 'javax'
ModuleNotFoundError: No module named 'javax'
Applet for add two numbers
How can you handle form in Spring 3.2 MVC?
how can i draw line between two panel contaning circle and line between their center?
Compare String with given String arraylists.
How to add BigDecimal in Java?

Ads