0

Consider the following bits of Java code:

for(ArrayList<String> str : strList) {
    // something
}

for(Iterable<String> str : strList) {
    // something
}

Depending on what happens inside the loop, it may well not be necessary to use ArrayList or List, but we can instead of Iterable.

Does this have a performance benefit or is it purely a conceptual thing where you define it to tell the reader of the code that this is all you'll ever be doing with the object?

1
  • No performance benefit. Commented Mar 9, 2017 at 1:08

1 Answer 1

1

It's purely conceptual. The language construct you're utilizing there requires the str object to implement the Iterable interface. Even if you pass an ArrayList (or subclass thereof), it's going to treat it as an Iterable

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for confirming

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.