yield() method pauses the currently executing thread temporarily for giving a chance to the remaining waiting threads of the same priority to execute. If there is no waiting thread or all the waiting threads have a lower priority then the same thread will continue its execution. Yield method doesn’t guarantee  that current thread will pause or stop. Don't think yield() is better than sleep() here.