Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Merge two array list

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 324
    Comment on it

     In the below example I have described "how to add or merge two array list?". Here I have created two array String  a[],String b[], then I have initialize values in array . After this I have created arrayList and merge value String a[] and String b[]. You can see below program it will clearly describe you How to Merge two array list.

    public class Add {
      public static void main(String args[]){
        String a[] = {"a", "b", "c"};
        String b[] = {"d", "e","f","g" };
    
        List<String> list = new ArrayList<String>(Arrays.asList(a));
     
     // here merge  String a[], String b[] values
    
        list.addAll(Arrays.asList(b));
        Object [] c = list.toArray();
        System.out.println(Arrays.toString(c));
       
      }
    }
    
     output :  [a, b, c, d, e, f, g]

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: