compare to arraylist java

Solutions on MaxInterview for compare to arraylist java by the best coders in the world

showing results for - "compare to arraylist java"
Lucas
17 Jan 2021
1import java.util.*;  
2public class ComapreArraylistExample1  
3{  
4	public static void main(String args[])  
5    {  
6      //first array list  
7      ArrayList<String> firstList=new ArrayList<String>();  
8      //adds elements to the arraylist  
9      firstList.add("Apple");  
10      firstList.add("Pears");  
11      firstList.add("Guava");  
12      firstList.add("Mango");
13      //second array list
14      List<String> secondList=new ArrayList<String>();  
15      //adds elements to the arraylist  
16      secondList.add("Apple");  
17      secondList.add("Pears");  
18      secondList.add("Guava");  
19      secondList.add("Mango");  
20      //comparing both lists  
21      boolean boolval = firstList.equals(secondList); 
22      //returns true because lists are equal  
23  	}  
24}