Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
AbstractList get() method in Java with Examples
Next article icon

AbstractList equals() method in Java with Examples

Last Updated : 26 Nov, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The equals() method of java.util.AbstractList class is used to compare the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order. Syntax:
public boolean equals(Object o)
Parameters: This method takes the object o as a parameter to be compared for equality with this list. Returns Value: This method returns true if the specified object is equal to this list. Below are the examples to illustrate the equals() method. Example 1: Java
// Java program to demonstrate // equals() method // for String value  import java.util.*;  public class GFG1 {     public static void main(String[] argv)         throws Exception     {          try {              // Creating object of AbstractList<String>             AbstractList<String>                 arrlist1 = new ArrayList<String>();              // Populating arrlist1             arrlist1.add("A");             arrlist1.add("B");             arrlist1.add("C");             arrlist1.add("D");             arrlist1.add("E");              // print arrlist1             System.out.println("First ArrayListlist : "                                + arrlist1);              // Creating another object of AbstractList<String>             AbstractList<String>                 arrlist2 = new ArrayList<String>();              // Populating arrlist2             arrlist2.add("A");             arrlist2.add("B");             arrlist2.add("C");             arrlist2.add("D");             arrlist2.add("E");              // print arrlist2             System.out.println("Second ArrayList : "                                + arrlist2);              // comparing first ArrayList to another             // using equals() method             boolean value = arrlist1.equals(arrlist2);              // print the value             System.out.println("Are both list equal : "                                + value);         }          catch (NullPointerException e) {             System.out.println("Exception thrown : " + e);         }     } } 
Output:
  First ArrayListlist : [A, B, C, D, E]  Second ArrayList : [A, B, C, D, E]  Are both list equal : true  
Example 2: Java
// Java program to demonstrate // equals() method // for Integer value  import java.util.*;  public class GFG1 {     public static void main(String[] argv)         throws Exception     {          try {              // Creating object of AbstractList<Integer>             AbstractList<Integer>                 arrlist1 = new ArrayList<Integer>();              // Populating arrlist1             arrlist1.add(10);             arrlist1.add(20);             arrlist1.add(30);             arrlist1.add(40);             arrlist1.add(50);              // print arrlist1             System.out.println("First ArrayListlist : "                                + arrlist1);              // Creating another object of AbstractList<Integer>             AbstractList<Integer>                 arrlist2 = new ArrayList<Integer>();              // Populating arrlist2             arrlist2.add(10);             arrlist2.add(20);             arrlist2.add(30);              // print arrlist2             System.out.println("Second ArrayList : "                                + arrlist2);              // comparing first ArrayList to another             // using equals() method             boolean value = arrlist1.equals(arrlist2);              // print the value             System.out.println("Are both list equal : "                                + value);         }          catch (NullPointerException e) {             System.out.println("Exception thrown : " + e);         }     } } 
Output:
  First ArrayListlist : [10, 20, 30, 40, 50]  Second ArrayList : [10, 20, 30]  Are both list equal : false  

Next Article
AbstractList get() method in Java with Examples

R

rohitprasad3
Improve
Article Tags :
  • Java
  • Java-Collections
  • Java - util package
  • Java-Functions
  • Java-AbstractList
Practice Tags :
  • Java
  • Java-Collections

Similar Reads

    AbstractList in Java with Examples
    The AbstractList class in Java is a part of the Java Collection Framework and implements the Collection interface and the AbstractCollection class. AbstractList class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a Rand
    7 min read
    AbstractList add(E ele) method in Java with Examples
    The add(E ele) method of AbstractList class in Java is used to insert the specified element to the end of the current list. Syntax: public boolean add(E ele) Where E is the type of element maintained by this AbstractList collection. Parameter: This method accepts a single parameter ele which represe
    2 min read
    AbstractList addAll() method in Java with Examples
    The addAll() method of java.util.AbstractList class is used to insert all of the elements in the specified collection into this list at the specified position. This shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elem
    5 min read
    AbstractList clear() method in Java with Examples
    The clear() method of java.util.AbstractList class is used to remove all of the elements from this list. The list will be empty after this call returns. Syntax: public void clear() Returns Value: This method does not return anything. Below are the examples to illustrate the clear() method. Example 1
    2 min read
    AbstractList equals() method in Java with Examples
    The equals() method of java.util.AbstractList class is used to compare the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e
    3 min read
    AbstractList get() method in Java with Examples
    The get() method of java.util.AbstractList class is used to return the element at the specified position in this list. Syntax: public abstract E get(int index) Parameters: This method takes index of the element as a parameter, the element at which is to be returned. Returns Value: This method return
    2 min read
    AbstractList hashCode() method in Java with Examples
    The hashCode() method of java.util.AbstractList class is used to return the hash code value for this list. Syntax: public int hashCode() Returns Value: This method returns the hash code value for this list. Below are the examples to illustrate the hashCode() method. Example 1: Java // Java program t
    2 min read
    AbstractList indexOf() method in Java with Examples
    The indexOf() method of java.util.AbstractList class is used to return the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if t
    3 min read
    AbstractList iterator() method in Java with Examples
    The iterator() method of java.util.AbstractList class is used to return an iterator over the elements in this list in proper sequence. This implementation returns a straightforward implementation of the iterator interface, relying on the backing list's size(), get(int), and remove(int) methods. Synt
    2 min read
    AbstractList lastIndexOf() method in Java with Examples
    The lastIndexOf() method of java.util.AbstractList class is used to return the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences