Sunday, December 8, 2019

What will be the output when you add String object in HashSet?

Problem statement: Given code is 
  1. public class Test {
  2. public static void main(String[] args) {
  3. HashSet<String> s = new HashSet<>();
  4. s.add("A");
  5. s.add("B");
  6. s.add("C");
  7. s.add("A");
  8.   System.out.println("Elements: \n" + s);
  9.   System.out.println("Size: " + s.size());
  10.   System.out.println("Objects: " + s);
  11. }
  12. }
Answer:
Elements: 
[A, B, C]
Size: 3
Objects: [A, B, C]

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...