educative.io

Why use fast==slow instead of slow.equals(fast)

Its more of a language question than data structure.
but is’nt it more accurate to .equals instead of == when comparing 2 objects?


Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: LinkedList Cycle (easy) - Grokking the Coding Interview: Patterns for Coding Questions

Hi @bee1,
Yes you are right comparing 2 objects using the .eqauls is more accurate if we are comparing 2 objects are identical or not. Here in this example we compares that two references are identical or not.

Thanks
And please let me Know if it is not clear yet.