Problem statement: Given code is
Elements:
[com.practice.core.C@7852e922, com.practice.core.A@15db9742, com.practice.core.B@6d06d69c, com.practice.core.A@4e25154f]
Size: 4
- import java.util.HashSet;
- class A {}
- class B {}
- class C {}
- public class Test {
- public static void main(String[] args) {
- HashSet set = new HashSet();
- set.add(new A());
- set.add(new B());
- set.add(new C());
- set.add(new A());
- System.out.println("Elements: \n" + set);
- System.out.println("Size: " + set.size());
- }
- }
Elements:
[com.practice.core.C@7852e922, com.practice.core.A@15db9742, com.practice.core.B@6d06d69c, com.practice.core.A@4e25154f]
Size: 4
No comments:
Post a Comment