Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Practice InterviewNew Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

WithoutBook Forum

Ques. how HashSet works for user defined objects and String objects.

- public final class HashTest {

private String str;

public HashTest(String str) {
this.str = str;
}

@Override
public int hashCode() {
return this.str.hashCode();
}

@Override
public boolean equals(Object obj) {

return this.str.equals(obj);
}

public static void main(String args[]) {
HashTest h1 = new HashTest("1");
HashTest h2 = new HashTest("1");
HashTest h3 = new HashTest("1");
HashTest h4 = new HashTest("1");

String s1 = new String("2");
String s2 = new String("2");

HashSet<Object> hs = new HashSet<Object>();
hs.add(h1);
hs.add(h2);
hs.add(s1);
hs.add(s

Posted on Jan 29, 2015 by lakshmi kanthreddy

Enter your Answer

Name
Email Address
Answer
©2019 WithoutBook