Possible Duplicate:
Java String.equals versus ==
I am writing a program to simulate the hare and turtle race! I am using getName() to see which objects thread is executing and based on that i increment the objects value. This is my code:
public void run()
{
try{
for(int i=0;i<100;i++)
{
System.out.println(Thread.currentThread().getName());
if(Thread.currentThread().getName() == "HARE")
{
hare++;
System.out.println("hare thread");
Thread.sleep(100);
if(hare == 49)
{
Thread.sleep(2000);
}
}
if(Thread.currentThread().getName() == "TURTLE")
{
turtle++;
Thread.sleep(250);
System.out.println("Turtle Thread");
}
The problem is that even thought it detects the name of the thread accurately but it never goes inside the if block. P.S I am new to java multithreading. Thank you for going through the code.