How can you add elements of two arrayLists in java?

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);
     }
    }









Related Tutorials/Questions & Answers:
How can you add elements of two arrayLists in java?
Display Different Elements from two ArrayLists in Java
Advertisements
Display Common Elements from two ArrayLists in Java
difference between java5 and java6 - Java Beginners
Java2
about java1
How to add two numbers in Java?
Add two number in java
Maven dependency for com.gooddata - gooddata-http-client version 1.0.0+java7 is released. Learn to use gooddata-http-client version 1.0.0+java7 in Maven based Java projects
Javah
How can we know the count/number of elements of an array?
Add two big numbers
How to add two calendars on the same html page
javaa swings - IDE Questions
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.
ModuleNotFoundError: No module named 'javax'
ModuleNotFoundError: No module named 'javax'
How do you combine two dictionary values for common keys
Compare String with given String arraylists.
how can I great two user and password in C++?
how can I great two user and password in C++?
how to add two object in a particular file - Java Beginners
How to make elements invisible ?
About Java2
Applet for add two numbers
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for javac-warning-annotation version 1.0.0
How do you add a numerical value to a regex
How would you read in and add all this into a list?
Maven dependency for com.episode6.mockspresso2 - plugins-javax-inject version 2.0.0-alpha05 is released. Learn to use plugins-javax-inject version 2.0.0-alpha05 in Maven based Java projects
Maven dependency for com.episode6.mockspresso2 - plugins-javax-inject version 2.0.0-alpha04 is released. Learn to use plugins-javax-inject version 2.0.0-alpha04 in Maven based Java projects
Maven dependency for com.episode6.mockspresso2 - plugins-javax-inject version 2.0.0-alpha03 is released. Learn to use plugins-javax-inject version 2.0.0-alpha03 in Maven based Java projects
Maven dependency for com.episode6.mockspresso2 - plugins-javax-inject version 2.0.0-alpha02 is released. Learn to use plugins-javax-inject version 2.0.0-alpha02 in Maven based Java projects
Maven dependency for com.episode6.mockspresso2 - plugins-javax-inject version 2.0.0-alpha01 is released. Learn to use plugins-javax-inject version 2.0.0-alpha01 in Maven based Java projects
Maven dependency for com.episode6.mockspresso2 - plugins-javax-inject version 2.0.0 is released. Learn to use plugins-javax-inject version 2.0.0 in Maven based Java projects
Maven dependency for com.episode6.mockspresso2 - plugins-javax-inject version 2.0.0-rc2 is released. Learn to use plugins-javax-inject version 2.0.0-rc2 in Maven based Java projects
Maven dependency for com.episode6.mockspresso2 - plugins-javax-inject version 2.0.0-rc1 is released. Learn to use plugins-javax-inject version 2.0.0-rc1 in Maven based Java projects
Maven dependency for com.episode6.mockspresso2 - plugins-javax-inject version 2.0.0-beta01 is released. Learn to use plugins-javax-inject version 2.0.0-beta01 in Maven based Java projects
Maven dependency for com.episode6.mockspresso2 - plugins-javax-inject version 2.0.0-alpha06 is released. Learn to use plugins-javax-inject version 2.0.0-alpha06 in Maven based Java projects
Java App - Add, Delete, Reorder elements of the buttons
Maven dependency for io.yupiik.uship - servlet-jakarta-javax-bridge version 1.0.16 is released. Learn to use servlet-jakarta-javax-bridge version 1.0.16 in Maven based Java projects
Maven dependency for io.yupiik.uship - servlet-jakarta-javax-bridge version 1.0.12 is released. Learn to use servlet-jakarta-javax-bridge version 1.0.12 in Maven based Java projects
Maven dependency for io.yupiik.uship - servlet-jakarta-javax-bridge version 1.0.8 is released. Learn to use servlet-jakarta-javax-bridge version 1.0.8 in Maven based Java projects
Maven dependency for io.yupiik.uship - servlet-jakarta-javax-bridge version 1.0.6 is released. Learn to use servlet-jakarta-javax-bridge version 1.0.6 in Maven based Java projects
Maven dependency for io.yupiik.uship - servlet-jakarta-javax-bridge version 1.0.9 is released. Learn to use servlet-jakarta-javax-bridge version 1.0.9 in Maven based Java projects
Maven dependency for io.yupiik.uship - servlet-jakarta-javax-bridge version 1.0.11 is released. Learn to use servlet-jakarta-javax-bridge version 1.0.11 in Maven based Java projects
Maven dependency for io.yupiik.uship - servlet-jakarta-javax-bridge version 1.0.10 is released. Learn to use servlet-jakarta-javax-bridge version 1.0.10 in Maven based Java projects

Ads