Need help with Java Questions Asked in Interviews

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rina0
    New Member
    • Jul 2023
    • 13

    Need help with Java Questions Asked in Interviews

    Hello everyone,

    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:

    Code:
    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:
    Code:
    1. Sachin Tendulkar
    2. Gautam Gambhir
    3. Ricky Ponting
    4. Shahid Afridi
    5. Kevin Pieterson
    6. MS Dhoni
    My goal is to sort the above Cricket Players' names based on their last names only. I would greatly appreciate any code or suggestions to achieve this sorting task.

    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/
Working...