Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




extend( ) FUNCTION


The extend( ) Function is used to add the elements of a new List to the end of the List.


Example :


x = ["Mohan", "Kriti", "Salim"]
y = ["Sia", "Andrew"]
x.extend(y)
print(x) 


Output :



  ['Mohan', 'Kriti', 'Salim', 'Sia', 'Andrew']

So, in the above code we have created a 'List' and initialised to the variable 'x'.


x = ["Mohan", "Kriti", "Salim"]

Below is how the values are positioned in the List,


java_Collections

Also we have another List that contains, 'Sia' and 'Andrew'.


y = ["Sia", "Andrew"]

java_Collections

Next, we have used the 'extend( )' function to add the new List 'y' that contains 'Sia' and 'Andrew' at the end of the List 'x'.


x.extend(y)

And the List 'y' is joined with 'x'.


java_Collections

And we get the below output,


['Mohan', 'Kriti', 'Salim', 'Sia', 'Andrew']