"If statement" problem in simple code?
Hi,
I am writing a simple homework program however am having some major problems with my "If" Statement and can not figure out why. I want my program to return a different variable if true yet it always says the statement is false. I Have it set up now in the test stage so that if false it prints out the two comparative variables in the Console and even though both variables are the same it still always says its false. Any ideas? Here are my two simple classes below. Thanks. And yes i know it doesn't go through the whole loop, it should not have to because in this test state the first variable it compares should be true.
--
import java.util.StringTokenizer;
public class PhoneList {
private static final String PHONE_BOOK = "mom:860-192-9876,bill:654-987-1234,mary:123-842-1100";
public static String getPhoneNumber(String name) {
//StringBuffer result = new StringBuffer();
StringTokenizer st = new StringTokenizer(PHONE_BOOK, ",:");
String[] tokens = new String[PHONE_BOOK.length()];
int c = 0;
String current = "";
while (st.hasMoreTokens()) {
current = st.nextToken();
tokens[c] = current;
c = c + 1;
}
for (int i = 0; i < c;) {
if (name == tokens) {
return "YES";
}
else {
return tokens + "|" + name;
}
//i=i+1;
}
return "NO";
}
}
--
public class Interface {
public static void main(String[] args) {
String hi = "mom";
System.out.println(PhoneList.getPhoneNumber(hi));
}
}
--

