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?
How to add two calendars on the same html page
how can i add hibernate plugin to eclipse?
How do you add a numerical value to a regex
how i can print the elements before a spicific value in array queue?
How would you read in and add all this into a list?
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.
Java2
how can you say java is secure
How many qusetions can you ask?
Can you tell me how it worked?
how can I great two user and password in C++?
how can I great two user and password in C++?
JavaScript Add Element to Array
Javah
how can add new line character into ajax response for java
how can add new line character into ajax response for java
How can you handle form in Spring 3.2 MVC?
Applet for add two numbers
how can i draw line between two panel contaning circle and line between their center?
ModuleNotFoundError: No module named 'javax'
ModuleNotFoundError: No module named 'javax'
Java App - Add, Delete, Reorder elements of the buttons
How to add BigDecimal in Java?
Compare String with given String arraylists.
How to add

Ads