Online Java Compiler By
JavaTpoint.com
import java.util.LinkedList; import java.util.List; public class JavaListEqualsExample1 { public static void main(String[] args) { List
list= new LinkedList<>(); for (int i=0;i<11;i++){ list.add(i); } List
list1= new LinkedList<>(); for (int i=0;i<11;i++){ list1.add(i); } //It returns a Boolean value true if both lists have the same elements and size.. Boolean bool=list.equals(list1); if (bool) { System.out.println("Both the lists are equal.\n" +"List : "+ list+"\n"+"List1 : "+list1); } else{ System.out.println("Both the lists are equal.\n" +"List : "+ list+"\n"+"List1 : "+list1); } } }
Output