Collection Interface equals() Method

Collection Interface equals() Method


Posted in : Java Posted on : November 25, 2010 at 11:50 AM Comments : [ 0 ]

This method is use to compare the specified object with this collection for equality.

Collection Interface equals() Method:

This method is use to compare the specified object with this collection for equality. It returns true if the invoking collection and obj are equal. Otherwise, returns false.

Syntax :

boolean equals(Object ob);

Example :

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

public class CollectionInterfaceEqualsMethod{

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

		arraylist.add(1);
		arraylist.add(2);
		arraylist.add(4);
		arraylist.add(5);
		arraylist.add(6);
		arraylist.add(7);
		arraylist.add(8);
		arraylist.add(9);
		if(arraylist.get(0).equals(1)){
			System.out.println("Value equals :"+arraylist.get(0));
		}
		else{
			System.out.println("Value not equals :"+arraylist.get(0));
		}		
	}
}

Output :

Value equals :1

Download This example code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics