Given below the sample code :
1. import java.util.*;
2. public class MyString {
3. private String a;
4. public MyString(String a) { this.a = a; }
5. public static void main(String[] args) {
6. HashSet<Object> hash = new HashSet<Object>();
7. MyString ms1 = new MyString("Roseindia");
8. MyString ms2 = new MyString("Roseindia");
9. String a1 = new String("Roseindia");
10. String a2 = new String("Roseindia");
11. hash.add(ms1); hash.add(ms2); hash.add(a1); hash.add(a2);
12. System.out.println(hash.size()); } }
What will be the output of the above code ?
1. 0
2. 1
3. 2
4. 3
(4)
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.