Compare two Lists

boolean equals(Object o)
Compares the specified object with this list for equality.

import java.util.ArrayList;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    List list = new ArrayList();

    list.add("1");
    list.add("2");
    list.add("3");
 
    list.add("java2s.com");


    List list1 = new ArrayList();

    list1.add("1");
    list1.add("2");
    list1.add("3");
 
    list1.add("java2s.com");
    

    System.out.println("List has:" + list);
    System.out.println("List1 has:" + list);

    boolean b  = list.equals(list1);
  
    System.out.println(b);
  }
}

The output:


List has:[1, 2, 3, java2s.com]
List1 has:[1, 2, 3, java2s.com]
true
Home 
  Java Book 
    Collection  

List:
  1. List interface
  2. Add element to List
  3. Clear a List
  4. Does it contain certain element
  5. Compare two Lists
  6. Get the element index
  7. Get Iterator from a List
  8. Remove element from List
  9. Get/set element
  10. List size and empty flag
  11. Get the sub list from a list
  12. Convert List to Array