I recently went through a Java Interview Questions resources and encountered a couple of queries for which I'm seeking answers and suggestions.
Query 1:
During the interview, I was presented with the following class:
Expand|Select|Wrap|Line Numbers
- java
- class CricketTeam{
- String name; //this is the complete name (inclusive of first and last name)
- }
Additionally, I was given a list of Cricket Players' names:
Expand|Select|Wrap|Line Numbers
- 1. Sachin Tendulkar
- 2. Gautam Gambhir
- 3. Ricky Ponting
- 4. Shahid Afridi
- 5. Kevin Pieterson
- 6. MS Dhoni
Query 2:
During the interview, I was asked to compare the advantages of using an enhanced for loop versus an iterator in Java. Specifically, I would like to know the benefits of using an enhanced for loop in Java and understand why it was introduced in the language in the first place, especially when the iterator is also available for similar tasks.
Thank you all in advance.
Resource link: If anyone is interested in referring to the Java Interview Questions resource I attended, you can find it here: https://www.interviewbit.com/java-interview-questions/