Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,011 questions

51,958 answers

573 users

How to join two ArrayList in Java

1 Answer

0 votes
import java.util.ArrayList;
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        ArrayList<Integer> al1 = new ArrayList<>(Arrays.asList(40, 89, 23, 99, 89)); 
        ArrayList<Integer> al2 = new ArrayList<>(Arrays.asList(7, 8, 2, 0)); 
        
        System.out.println(al1); 
        System.out.println(al2); 
        
        ArrayList<Integer> al12 = new ArrayList<Integer>();
        
        al12.addAll(al1);
        al12.addAll(al2);
        
        System.out.println(al12); 
   
    }
}
     
     
   
     
     
/*
run:
     
[40, 89, 23, 99, 89]
[7, 8, 2, 0]
[40, 89, 23, 99, 89, 7, 8, 2, 0]

*/

 



answered Aug 22, 2021 by avibootz
edited Aug 22, 2021 by avibootz

Related questions

2 answers 140 views
140 views asked Nov 26, 2023 by avibootz
1 answer 89 views
1 answer 86 views
86 views asked Mar 12, 2023 by avibootz
1 answer 128 views
128 views asked Mar 12, 2023 by avibootz
1 answer 129 views
1 answer 168 views
168 views asked Jun 28, 2020 by avibootz
2 answers 166 views
...