11:04 am - Sunday April 30, 2017

Compare two sets in LinkedHashSet using boolean equals(Object o)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

                              The method public boolean equals(Object o) compares the two sets and checks  whether the size of sets are same and the elements  present in the sets are equal.Returns true if they are same,otherwise returns false.

Example Program


import java.util.LinkedHashSet;

public class LinkedHashSetequals 

{

	public static void main(String args[]) 
	
	{

		LinkedHashSet lh = new LinkedHashSet();

		lh.add("Add");

		lh.add("Sub");

		lh.add("Mul");

		LinkedHashSet lhs = new LinkedHashSet();

		lhs.add("Add");

		lhs.add("Mul");

		lhs.add("Exp");

		boolean isequal = lh.equals(lhs);

		System.out.println("Is twosets equal: " + isequal);

	}

}


Output

      Is two sets equal: false

BACK

Filed in: Java Examples

Comments are closed.