Pages

Monday, 25 November 2019

How to Add/Join/Combine two arraylist? Core java Interview question? Top 5 programming qus on Arraylist?

Let there are two array list and we need to add value of both arraylist into one:

 // use import java.util.ArrayList;

public class AddTwoArrayList
{
    public static void main(String [] args)
    {
        //First ArrayList
        ArrayList<String> arraylist01=new ArrayList<String>();
        arraylist01.add("Kist1");
        arraylist01.add("Kist2");
        arraylist01.add("Kist3");

        //Second ArrayList
        ArrayList<String> arraylist02=new ArrayList<String>();
        arraylist02.add("Nist1");
        arraylist02.add("Nist2");
        arraylist02.add("Nist3");

        //Combined ArrayList
        ArrayList<String> arraylistCombined= new ArrayList<String>();
        arraylistCombined.addAll(arraylist01);
        arraylistCombined.addAll(arraylist02);

        //Displaying elements of the joined ArrayList
        for(String temp: arraylistCombined){
            System.out.println(temp);
        }
    }
}
 

*************************************************

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions

No comments:

Post a Comment