Member-only story
Refreshing Core Java: A Quick Revision for Experienced Developers — 2
Refreshing Core Java: A Quick revision for Experienced Developer — 1 : Link
Below are 20 Java questions for experienced developers, along with their answers:
1. What is the difference between Iterator and ListIterator in Java?
Answer:
Iteratorallows iteration in one direction (forward) and can be used with anyCollection(e.g.,List,Set).ListIteratoris an extension ofIteratorand allows bidirectional iteration (forward and backward). It can only be used withListcollections and also allows modification of the collection while iterating.
2. What is the purpose of the clone() method in Java?
- Answer: The
clone()method is used to create a copy (clone) of an object. By default, theclone()method performs a shallow copy, meaning the object’s fields are copied, but the references to objects inside the object are not cloned (they point to the same memory address).