Showing posts with label ArrayList. Show all posts
Showing posts with label ArrayList. Show all posts

Sunday, December 8, 2019

What will be the output when we add elements in collection of ArrayList in java?

Problem statement: In given java code, can you please let me know, what will be the output.
  1. import java.util.ArrayList;
  2. class A {}
  3. class B {}
  4. class C {}
  5. public class Test {
  6. public static void main(String[] args) {
  7. ArrayList list = new ArrayList();
  8. list.add(new A());
  9. list.add(new B());
  10. list.add(new C());
  11.   list.add(new A());
  12. System.out.println(list);
  13.   System.out.println("Size: " + list.size());
  14. }
  15. }
Answer:
[com.practice.core.A@15db9742, com.practice.core.B@6d06d69c, com.practice.core.C@7852e922, com.practice.core.A@4e25154f]
Size: 4

Note: fully_qualified_class_name@hashcode_value

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...